C2664 when casting child class to templated parent class
- by DC
I have a parent class which is templated, and a child class which implements it.
template< typename T1, typename T2>
class ParentClass{ . . . };
class ChildClass : public ParentClass<MyT1, MyT2> { . . . };
And I want to have a pointer which I can use polymorphically:
ParentClass<T1, T2>* ptr;
ptr = static_cast<ParentClass<MyT1, MyT2>* >(new ChildClass() );
No matter how I cast it, I always get a C2664 which has the same expression:
error C2664: cannot convert parameter 1 from 'ParentClass< T1,T2 *' to 'ParentClass< T1,T2 *'
Is it not possible to cast pointer types between inherited types if the parent is templated, even if the types specified in the templates are the same?