您的位置:首页 > 其它

VS2005 warning C4251 needs to have dll-interface

2008-12-22 13:07 453 查看
程序中消除warning有两种方法:消极一点不去理他,反正不是error:-);积极一点,则想办法去掉。去掉又用两种方法:一种使用#pragma warning(disable: xxxx),眼不见,心不烦;另外就是找出解决问题的办法了。
今天做dll库时,在struct中用到了stl:
class CLASS_TEST
{
...
private:
std::vector<MY_STRUCT> m_structs;
}
但是编译时,vs2005给出了warning C4251: 'CLASS_TEST::m_structs' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class ‘CLASS_TEST’的警告信息。费了很大的劲才解决掉,记录下来。

在头文件中,定义宏
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif

现在,在变量m_structs前,添加:
template class MYDLL_API std::allocator<myStruct>;
template class MYDLL_API std::vector<myStruct, std::allocator<myStruct> >;
这样,即可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐