You must change the base type to be polymorphic:
class Base {
public:
Base() {};
virtual ~Base(){};
};
To cast from some supertype to some derived type, you should use dynamic_cast
:
Base *b = new Derived<int>(1);
Derived<int> *d = dynamic_cast<Derived<int> *>(b);
Using dynamic_cast
here checks that the typecast is possible. If there is no need to do that check (because the cast cannot fail), you can also use static_cast
:
Base *b = new Derived<int>(1);
Derived<int> *d = static_cast<Derived<int> *>(b);