This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: dynamic_cast
- From: bjorn rohde jensen <shamus at tdcadsl dot dk>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 16 Feb 2002 15:18:53 +0100
- Subject: Re: dynamic_cast
- References: <02021614573401.00765@mephisto>
- Reply-to: shamus at tdcadsl dot dk
Hi Sebastian,
You can only use RTTI on instances of a class with a
virtual table, that is has at least one virtual function,
even if you don't actually need one. You should not
delete an instance of a polymorphic class without a
virtual destructor through a pointer or reference to
an instance of a base class, as this will only ensure
the base class destructor is run. Check Meyers effective
C++ books.
Yours sincerely,
bjorn
Sebastian Huber wrote:
>
> Hello,
> why does the following code fragment not work?
>
> class Storable { };
>
> class Component : virtual public Storable { };
>
> int main()
> {
> Storable* s = new Component();
> Component* c = dynamic_cast<Component*>( s);
> delete s;
>
> return 0;
> }
>
> This code is very similar to an example of Bjarne Stoupstrup.
> I use g++ version 2.95.3.