template<typename Type>
class List
{
public:
List(void);
~List(void);
...
}
which inherited by
template<typename Type>
class LinkedList : public List<Type>
{
public:
LinkedList(void);
~LinkedList(void);
...
}
but when I
List<int>* list = new LinkedList<int>();
there comes
error LNK2019: unresolved external symbol "public: __thiscall LinkedList<int>::LinkedList<int>(void)" (??0?$LinkedList@H@@QAE@XZ) referenced in function _wmain
I know that for template, the type is determined when compiling, I feel it should be ok to determine typename Type when compiling and then determine the derived class type at runtime. Is it possible to use polymorphism with template class in this way?
////////////////////////////////////////////////////////////////////////////////
Thank hkaiser and Chubsdad, it is the linking problem. I defined the constructor in the cpp file, but somehow the linker cannot detect it. And I tried to move it to the header file, it worked, but I don't like that. It seems to be ok if I define the functions in cpp with a resolved type, like:
LinkedList<int>::LinkedList(void)
:List<int>()
{
mHead = new Node<int>(0);
}
instead of:
template<typename Type>
LinkedList<Type>::LinkedList(void)
:List<Type>()
{
mHead = new Node<Type>(0);
}
But what's the difference? Why it becomes invisible with the template defination while visible with a resolved one? Is it possible to define template member functions in cpp?