If I wanted to allocate memory for a class and then call its constructor as two separate steps, while still having the object be managed by the garbage collector, is there any way to do that?

I believe that I've figured out a way to accomplish the first step, but not the second.

import std.stdio;

class Foo {
    this(string bar) {
        writeln(bar);
    }
}

void main() {
    Foo f = (new Foo[1])[0];
    f("Hello"); // doesn't compile
}

Reply via email to