error C2252: 只能在命名空间范围内显式实例化模板

今天在搞毕设时,运行网上的一个SDK,出现如下的错误提示

error C2252: 只能在命名空间范围内显式实例化模板

网上查了下,是这个错误是由于vs2010全局命名空间中找不到要导出的STL类。修改很简单:将需要导出的STL类从自定义的类中移动到全局命名空间中。

template class __declspec(dllexport) std::allocator<std::string>;
template class __declspec(dllexport) std::vector<std::string, std::allocator<string>>;
template class __declspec(dllexport) std::allocator<SaveInfo>;
template class __declspec(dllexport) std::vector<SaveInfo>;
template class __declspec(dllexport) std::allocator<int>;
template class __declspec(dllexport) std::vector<int, std::allocator<int>>;
class __declspec(dllexport) SingleObjectDetection
{
public:
	//template class __declspec(dllexport) std::allocator<std::string>;
	//
	//

	SingleObjectDetection(void);
	~SingleObjectDetection(void);

	int start(std::string path);
	int getOneFrame(FrameInfo& param);
	bool pushOneInfo(const SaveInfo& param);
	bool saveInfoToFile(const std::string savePath,int EvaluateType);
	void stop();
	std::string directoryPath_;
	bool isInit_;
private:
	bool isInit() const;

private:
	
	
	std::vector<std::string> imagePathSet_;
	int imagePathSetIndex_;
	std::vector<SaveInfo> saveInfoSet_;
	std::vector<int> randomSet_;
};

将模板实例化部分的放置于全局作用空间,通过编译。

VS2008中不会认为第一种代码是错误,从VS2010开始才将它作为


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章