Hello,
Environment: Visual Studio 9, C++ without managed extensions.
I've got a third-party library which exports a fully-specialized template class MyClass<42>
defined in MyClass.h. It gets compiled into a helper loader .lib and a .dll file. The .lib file contains compiled code for this specialization, and necessary symbols. The MyClass.h looks like this:
template<UInt D>
class MyClass {
public:
MyClass() {...};
virtual ~MyClass() {};
}
Now I'd like to use this library. If I include the MyClass.h in a Client.cpp and then compile it, I'll get second copy of these symbols in the Client.obj file. I can get rid of these symbols by defining all the member of that specialization as "extern". My Client.cpp looks like this:
#include <ThirdParty/MyClass.h>
extern template class MyClass<42>;
extern template MyClass<42>::MyClass<42>();
extern template MyClass<42>::~MyClass<42>();
void MyFunction(MyClass<42>& obj) {...}
The problem is that I cannot get rid of the virtual destructor this way. For the virtual destructor I get an almost standard LNK2005 error:
ThirdPartyd.lib(ThirdPartyd.dll) : error LNK2005:
"public: virtual __thiscall MyClass<42>::~MyClass<42>(void)"
(??1?$MyClass@$01@@@UAE@XZ) already defined in Client.obj
What should I do?