On 11/3/22 08:40, H. S. Teoh wrote:

> D does not have the equivalent of C++'s allocating a class instance on
> the stack.

Not by default but we have two different ways, either may be discouraged:

import std.typecons : scoped;
import std.stdio;

class C {
    int i;
}

void main() {
    // Either this:
    // auto c = scoped!C();

    // Or this:
    scope c = new C();

writeln("If the address values are close, then the object is on the stack:");
    writeln(&c);
    writeln(&c.i);
}

Ali

Reply via email to