> Fabien Costantini wrote:
> >> Albrecht Schlosser wrote:
> >>> ...
> >>> What happens? Note that img points to an Fl_Shared_Image object.
> >>> The compiler can't detect this, can it? Will the Fl_Shared_Image
> >>> be destroyed?
> >> Yes, it will, since the destructor of a class is always virtual.
> > Always virtual ?
>
> Yes, always.  Otherwise inheritance would not work correctly (all
> destructors are called up through the root class...)
>
> --
> ______________________________________________________________________
> Michael Sweet, Easy Software Products           mike at easysw dot com
Yes, I agree that at one class level all derived class destructor are 
(fortunately) called.
So say C inherits from B that inherits from A.
if C destructor is invoked, then B and A destructor are called.

But what I meant here is that you have to explicitly add the 'virtual' keyword 
to base class A if you want this:
C *c = new C();;
B * b=c;
delete b; // will call B and A destructor only if A destructor is not virtual

// but if A destructor is explicitly defined as virtual, then C,B and A 
destructors will be called.

Fabien


_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to