This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: dynamic_cast to another base class


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]