我明白爲什麼我有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