Re: A solution to warning C4251 - class needs to have dll-interface...?



Thank you, Doug! Your answer is very helpful to me :-)

Doug Harrison [MVP] wrote:
[...] Think about the motivation for this warning. It's
emitted when you use a non-dllexported class X in a dllexported class
Y. What's so bad about that? Well, suppose Y has an inline function
y_f that calls a function x_f belonging to X that is not also inline.
If y_f is inlined inside some client that doesn't statically link X,
the link will fail, because x_f won't be found.

It sounds like this scenario won't happen when using an STL container within
my dllexported class, right? Because the functions of the STL containers
are completely defined by their header files. We're using both VC++ 7.1 and
8.0, with the included STL.

Anyway, you're just talking about link errors, right? I was afraid that the
warning indicated that my program might have runtime crashes! Especially
because of Q172396, "You may experience an access violation when you access
an STL object through a pointer or reference in a different DLL or EXE".
http://support.microsoft.com/kb/q172396/

Q172396 says: "Most classes in the Standard C++ Libraries use static data
members..." Apparently this is the cause of those access violations. So
you should never return a reference to an STL container from an dllexported
class, right? Is it even unsafe to return a reference to an std::string,
or a reference to a vector?

Kind regards,

Niels


.


Loading