
export classes using std namespace (ex std::vector) in a DLL
Quote:
>Hello,
>I'm trying to create a DLL. I want my classes to be
>accessible (using __declspec(dllexport)).
>The problem is that "the class std::vector needs to have
>dll-interface to be used by clients of class c..."
>What can I do to avoid this message ?
#pragma warning(disable) can help. :) As std::vector is a template, it can
be instantiated everywhere it's needed, and it's not the end of the world.
The situation is that the DLL and its client have their own independent
vector code implementations. (Template static data is another issue, but
vector has none, so you're safe in that respect) What does this imply? Two
things. There is some code bloat, which is minimal for a class like vector.
Potentially more troublesome is the versioning aspect. To avoid the DLL and
its clients getting out of step in their vector implementations, you
shouldn't, say, update your compiler and then compile one but not the other.
But hey, you're using __declspec(dllexport) on a class, so you pretty much
can't do that anyway. So you're left with a probably insignificant code
bloat issue. To fix that, you could explicitly instantiate and export all
the template specializations your exported classes use, but that gets to be
a pain. It's easy to forget, and there are other contexts in which the
compiler won't warn about cross-module usage. So I wouldn't feel too bad
about ignoring the warning.
P.S. Please include the warning number in future messages. For example, this
one is C4251. Makes it easier to google. :)
--
Doug Harrison
Microsoft MVP - Visual C++