Delay allocating class instance in stack.
ANtlord via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 21 01:08:24 PDT 2017
Hello! I read documentation about memory management and can't
find description about delay allocation of instance. I have a
method marked by @nogc. This method takes boolean variable. If
this variable is true I want to construct object with one set of
parameters else I want to construct object with another set of
parameters. Take a look at code for clearance.
void method(bool flag) @nogc
{
scope MyClass obj;
if(flag) {
obj = new MyClass(1);
} else {
obj = new MyClass(2);
}
// using obj
}
But this code CAN'T be compiled. How should I declare object for
delay construction.
Thanks.
More information about the Digitalmars-d-learn
mailing list