The following piece of code usually triggers warning C4251:
'MyClass::m_object' : class 'ThirdPartyTemplate<T>' needs to have
dll-interface to be used by clients of class 'MyClass':
template <typename T>
class ThirdPartyTemplate
{
public:
// Constructor.
ThirdPartyTemplate() {}
};
class __declspec(dllexport) MyClass
{
ThirdPartyTemplate<int> m_object; // warning C4251!
};
Is there really anything wrong about it? Here at LKEB (www.lkeb.nl), we
often get this kind of warning, when using Boost or STL. Now it appears
that one can get rid of the warning, by wrapping the ThirdPartyTemplate<int>
object inside a simple struct:
struct WrapperStruct
{
ThirdPartyTemplate<int> wrappedObject;
};
class __declspec(dllexport) MyClassWithoutWarning
{
WrapperStruct m_wrapper; // No warning! :-)
};
Does this approach really solve the problem, or does it only hide the
message?
Kind regards,
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center