Polymorphism with templated classes
I'm trying to define a variable type at runtime based on user input, so what I did was created an abstract base class Variable and derived a templated class from it.
Code:
class Variable
{
public:
virtual ~Variable() = 0;
};
template<class T>
class Data : public Variable
{
public:
Data();
virtual ~Data();
protected:
T value;
};
This way I can get the input, determine what type to use, and then do something like
Code:
Variable* var;
var = new Data<int>;
and then add all the variables to a map<string,Variable*>. My problem is that when I try to compile the linker gives me this error:
Quote:
Error LNK2019: unresolved external symbol "public: _thiscall Data<int>::Data<int>(void)" (??0?Data@H@@QAE@XZ) referenced in function "protected: void _thiscall Console::def(void)" (?def@Console@@IAEXXZ)
My constructor for Data looks like this
Code:
template<class T>
Data<T>::Data()
{
}
Why isn't the linker able to use my constructor? Is polymorphism even possible with a derived templated class?