dynamic_cast
bjorn rohde jensen
shamus@tdcadsl.dk
Sun Feb 17 14:37:00 GMT 2002
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.
More information about the Gcc-help
mailing list