我明白为什么我有C4251警告,当我编译我的代码为here解释。我的问题是,如果可访问的导出类成员来自STL,我们可以忽略C4251警告吗?我举一个简单的例子来说明我的问题:在这种情况下,我可以忽略C4251警告吗?
dll.h
#include <iostream>
#include <string>
using namespace std;
class __declspec(dllexport) HelloWorld
{
public:
string name;
HelloWorld();
HelloWorld(const string &str);
};
dll.cpp
#include "dll.h"
HelloWorld::HelloWorld()
{
name ="";
}
HelloWorld::HelloWorld(const string &str)
{
name = str;
}
我已经获得的警告信息是如下:
Warning 1 warning C4251: 'HelloWorld::name' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'HelloWorld' *\dll.h 9
我的问题是:我可以忽略这个警告吗?我如何使用这个库的方式也很简单:
#include "dll.h"
#include <iostream>
using namespace std;
int main(void)
{
HelloWorld myworld;
myworld.name = "Tom's world";
cout<<myworld.name<<endl;
return 0;
}
只是第一点 - 我不会把'using namespace std'放在头文件中。它强制你的头文件的所有用户把这个名字空间导入他们的代码中。 – 2013-05-03 15:28:12
就个人而言,如果API *很简单,我根本不会使用'std :: string',而是坚持使用'char'等外部接口。 – 2013-05-03 15:29:05