In a plugin-based C++ project, I have a TmpClass
that is used to exchange data between the main application and the plugins. Therefore the respective TmpClass.h
is included in the abstract plugin interface class that is included by the main application project, and implemented by each plugin.
As the plugins work on STL vectors of TmpClass
instances, there needs to be a default constructor and destructor for the TmpClass
. I had declared these in TmpClass.h
:
class TmpClass {
TmpClass();
~TmpClass();
}
and implemented them in TmpClass.cpp
.
TmpClass::~TmpClass() {}
TmpClass::TmpClass() {}
However, when compiling plugins this leads to the linker complaining about two unresolved externals - the default constructor and destructor of TmpClass
as required by the std::vector<TmpClass>
template instantiation - even though all other functions I declare in TmpClass.h
and implement in TmpClass.cpp
work. As soon as I remove the (empty) default constructor and destructor from the .cpp file and inline them into the class declaration in the .h file, the plugins compile and work.
Why is it that the default constructor and destructor have to be inline for this code to compile? Why does it even maatter? (I'm using MSVC++8).