Open apavlenko opened 8 years ago
A possible solution is described here: http://stackoverflow.com/questions/16419318/one-way-of-eliminating-c4251-warning-when-using-stl-classes-in-the-dll-interface
I think you've got at least three possible options to solve this problem:
#pragma
statements.C4251
warning, in a way that is described here. In short you would have to insert following lines of code before your HelloWorld class
:...
#include <vector>
template class __declspec(dllexport) std::allocator<int>;
template class __declspec(dllexport) std::vector<int>;
template class __declspec(dllexport) std::string;
class __declspec(dllexport) HelloWorld
...
By the way, the order of those exports seems to be important: the vector class template uses the allocator class template internally, so the allocator instantiation has to be exported before the vector instantiation.
int *p_abc;
int abc_len;
in something like class MyFancyDataArray and the fields
char *p_str;
int str_len;
in something like class MyFancyString
, then this would be a more decent solution (similar to the one described at the second point). But it is probably not the best habit to reinvent the wheel too often.
A warning "warning C4251: 'XXX' : class 'std::YYY<...>' needs to have dll-interface to be used by clients of class 'XXX'" says that due to several binary-incompatible STL versions on Windows (per VS version) this is dangerous.