bluedalmatian
June 3rd, 2007, 12:12 AM
I've got several classes, call them B, C, D which all inherit from A.
Given a pointer to A
A* aninstance;
I need to check which subclass it points to which Im trying to do like this:
if ( (B* bp = (dynamic_cast<B*>(aninstance)) )
{
//its an instace of B
}
But the compiler is saying:
cannot dynamic_cast aninstance (of type ‘class A*’) to type ‘class B*’ (source type is not polymorphic).
What have I done wrong?
Thanks
Given a pointer to A
A* aninstance;
I need to check which subclass it points to which Im trying to do like this:
if ( (B* bp = (dynamic_cast<B*>(aninstance)) )
{
//its an instace of B
}
But the compiler is saying:
cannot dynamic_cast aninstance (of type ‘class A*’) to type ‘class B*’ (source type is not polymorphic).
What have I done wrong?
Thanks