Separate allocation and construction?
Chris Williams via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 5 15:22:15 PDT 2014
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
}
More information about the Digitalmars-d-learn
mailing list