exporting C++ classes from a DLL


Alfonso Morra

I have a class declared as ff:

class __declspec(dllexport) A {
A() ;
A(const A&)
A& operator=(const A&) ;
~A() ;

void doThis(void) ;
void doThat(void) ;

std::string s ;
std::vector< <std::pair> > vp ;

When I compile the code, the compiler generates several warnings such as:

warning C4251: 'A::s' : class 'std::basic_string<_Elem,_Traits,_Ax>'
needs to have dll-interface to be used by clients of class 'A'

etc. Why do I have to export private variables (is that what the warning
message is instructing me to do?)

Despite the warnings, the code builds and the dll is built. When I use
the dll in another project, problems (unsuprisingly) arise but they are
of a slightly different kind. One of the class methods is anoverloaded
function template method. This does not seem to be exported and I am
getting a link error when I try to link to A.lib so I can create a
project that uses classes exported by A.dll

Any pointers will be appreciated. Tks

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question