Re: Polymorphism
From: James Dennett (jdennett_at_acm.org)
Date: 12/11/04
- Next message: James Dennett: "Re: Newbie question on visual studio"
- Previous message: James Dennett: "Re: howto get object-pointers from iterators?"
- In reply to: B. v Ingen Schenau: "Re: Polymorphism"
- Next in thread: Anthony Borla: "Re: Polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 11 Dec 2004 10:17:13 -0800
B. v Ingen Schenau wrote:
> Rich wrote:
>
>
>>Hello,
>>
>>I am intrigued by this post and the program :)
>>
>>I have not really got as far as polymorphism yet, but a google says
>>something about setting the base class destructor as virtual as well
>>and then also making derived classes destructors virtual
>>
>>something to do with making the whole chain of destructors being
>>called.
>>
>>So I am thinking that if the Base class destructor is not made virtual
>>then when delete is called it won't call the derived classes
>>destructor but it's own one instead?
>
>
> Yes, that is what typically will happen.
> Officially it is undefined behaviour, so anything could happen.
A long time ago I posted an example of an inheritance hierarchy
in which omitting the "virtual" keyword from a destructor would
give a crash on all the systems on which I tested it; this is
not just a theoretical problem. That said, if you stick to
single inheritance, and common compilers, then you'll probably
just get a call to the wrong destructor.
-- James
- Next message: James Dennett: "Re: Newbie question on visual studio"
- Previous message: James Dennett: "Re: howto get object-pointers from iterators?"
- In reply to: B. v Ingen Schenau: "Re: Polymorphism"
- Next in thread: Anthony Borla: "Re: Polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|