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

Reply via email to