digitalmars.D.learn - Is it possible to call a parent's destructor?
- Gary Willoughby (2/2) Jan 11 2014 Is it possible to call a parent's destructor? If so what's the
- Adam D. Ruppe (27/29) Jan 11 2014 Parent destructors are called automatically:
Is it possible to call a parent's destructor? If so what's the syntax?
Jan 11 2014
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