dynamic_cast to another base class

John Love-Jensen eljay@adobe.com
Wed Mar 8 14:03:00 GMT 2006


Hi Aseem,

> Class C doesn' t have virtual functions BUT has a virtual destructor.

A virtual destructor fulfills the requirement for the class to have a
virtual function table, so that there is a place (off the virtual function
table) to hold the object's type information.

And, hence, that the class is a polymorphic class, which is required to use
the dynamic_cast.

> Can you point me to some literature which explains as to why
> dynamic_cast requires virtual functions ?

p409 (section 15.4.1) in Stroustrup's C++ programming Language (Special
edition) mentions the requirement that the pointer's type be polymorphic.

Sincerely,
--Eljay



More information about the Gcc-help mailing list