www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is it possible to call a parent's destructor?

reply "Gary Willoughby" <dev nomad.so> writes:
Is it possible to call a parent's destructor? If so what's the 
syntax?
Jan 11 2014
parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Saturday, 11 January 2014 at 18:38:22 UTC, Gary Willoughby 
wrote:
 Is it possible to call a parent's destructor? If so what's the 
 syntax?
Parent destructors are called automatically: import std.stdio; class Foo { ~this() { writeln("Foo.dtor"); } } class Bar : Foo { ~this() { writeln("Bar.dtor"); } } void main() { auto f = new Bar(); } $ ./test500 Bar.dtor Foo.dtor But if you want to do it explicitly, you can with "super.__dtor(); class Bar : Foo { ~this() { writeln("Bar.dtor"); super.__dtor(); } } Notice that it is still called automatically, so it goes twice: Bar.dtor Foo.dtor Foo.dtor
Jan 11 2014