-
Template problem
class CAnyBaseClass
{
public:
CAnyBaseClass();
~CAnyBaseClass();
};
// Definitions ...
template<class BASE>
class CMyClass : public BASE
{
public:
CMyClass();
~CMyClass();
};
// Definitions etc...
...
CMyClass<CAnyBaseClass>* pMyClass = new CMyClass<CAnyBaseClass>;
causes LNK2019 linker error.
I don`t know what to do!
Please, help !
-
prolly your defintions there which you haven't posted
-
With definitions I mean definitions of constructor and destructor
CAnyBaseClass::CAnyBaseClass()
{
}
CAnyBaseClass::~CAnyBaseClass()
{
}
and
CMyClass::CMyClass()
{
}
CMyClass::~CMyClass()
{
}
I have just written them only to avoid compiler error, so I haven`t written any specific code inside them.
I tried to put the defintions in the header file of the class, and that avoided the error. But when they were in the .cpp file, linker gives error.
-
don't forget that CAnyBaseClass is a template class, the function definitions are thus templates as well
-
ALL template code goes in headers, always. Since the template code is only compiled when it is used in your program, if you put it in a source file, it wont be found when the compiler tries to compile it. It will compile, since the prototype exists, but the implementation is not there.
Z.
-