On Wednesday, 21 March 2018 at 14:04:58 UTC, Adam D. Ruppe wrote:

In Simen's example, the child information is not available at compile time. This line here:

A a = new B();

discards the static type. The compiler could probably cheat and figure it out anyway in this example, but suppose:

[snip]

There are a few interesting things in the class destructor part of the spec.

For instance:
"There can be only one destructor per class, the destructor does not have any parameters, and has no attributes. It is always virtual."
If the destructor has no attributes, how can it be @nogc?

Also:
"The destructor for the super class automatically gets called when the destructor ends. There is no way to call the super destructor explicitly." This means that you can't write something like below. Actually below gives the correct error. The problem is that if you remove the @nogc on A, then the result is wonky (and no compile-time error) and if they both have @nogc then you can't call destroy.

import std.stdio : writeln;

class A
{
    @nogc ~this()
    {
        writeln("destroy A");
    }
}

class B : A
{
    ~this()
    {
        writeln("destroy B");
        destroy(super);
    }
}

void main()
{
    A a = new B;
}

Reply via email to