struct A {};
struct B : A {};
int main()
{
A* a = new B();
B* b = dynamic_cast<B*>(a);
}
gives:
cannot dynamic_cast 'a' (of type 'struct A*') to type 'struct B*' (source type is not polymorphic)
How can I make A
polymorphic? I want to safely cast it to B.
(One way is to add a dummy virtual function, but is there a better way?)