Adr*_*ire 7 c++ dll stl compiler-errors c++11
我想在DLL中实现一个简单的类,如:
class MY_EXPORT_IMPORT MyClass
{
public:
//std::string anyPublicStr; //see point 3
protected:
std::string anyStr;
};
Run Code Online (Sandbox Code Playgroud)
问题是Visual C++编译器(在本例中为2013)会抛出以下警告:
C:... MyClass.hpp:X:警告:C4251:'MyClass :: postfix':类'std :: basic_string,std :: allocator>'需要让struct'MyClass的客户端使用dll接口"
我阅读了几个论坛,了解为什么会显示此警告以及如何解决此问题.但我仍不清楚:
就个人而言,我不明白为什么这个类不能静态链接所需的STL库并使其工作而不导出任何东西.或者如果STL是动态链接的,它也应该在dll中自动链接.
这是警告的原因?怎么解决?
std::string 只是一个 typedef:
typedef basic_string<char, char_traits<char>, allocator<char> >
string;
Run Code Online (Sandbox Code Playgroud)
关于在 dll 接口边界上使用 STL,通常如果避免这样做会更简单,而且如果可能的话我个人更喜欢它。但编译器只是给你一个警告,并不意味着你会遇到问题。看一下:DLL 和 STL 以及静态数据(天哪!)