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開始纔將它作爲


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