D classes inherane. How it works.

Jason House jason.james.house at gmail.com
Tue Apr 8 20:04:52 PDT 2008


It should always be considered an error to call a virtual member function in a destructor. Someone should make a bug report for this. I would if I was at a computer and not typing with my thumb...

Lionello Lunesu Wrote:

> 
> "Gregor Richards" <Richards at codu.org> wrote in message 
> news:ftga4f$1gbn$1 at digitalmars.com...
> > Every destructor in the hierarchy will be called. I don't recall if you 
> > can do something like ~super(), but the default is exactly as you see: 
> > bottommost destructor to topmost destructor. flush() in A is being called 
> > because ~this() in A calls it.
> >
> > So, you have to make sure that B's destructor doesn't destroy any data 
> > that is in fact owned by its parent class, A. Why would you, though?
> 
> But it appears B's flush is being called, not A's, and B's data is 
> definately destroyed, because ~B was called before it. Likewise, B's init is 
> called before B's ctor!
> 
> I find it all very worrying. It's a good thing I avoid inheritance like the 
> plague lately.
> 
> L. 
> 




More information about the Digitalmars-d mailing list