January 11, 2014 Is it possible to call a parent's destructor? | ||||
---|---|---|---|---|
| ||||
Is it possible to call a parent's destructor? If so what's the syntax? |
January 11, 2014 Re: Is it possible to call a parent's destructor? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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
|
Copyright © 1999-2021 by the D Language Foundation