This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: dynamic_cast to another base class
- From: John Love-Jensen <eljay at adobe dot com>
- To: Aseem Rastogi <aseem at india dot tejasnetworks dot com>
- Cc: MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Wed, 08 Mar 2006 08:03:28 -0600
- Subject: 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