Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns.

Take this for example:

class MyClass{
int x = 2;
}

And then in app.d

ref MyClass doStuff(){
MyClass mc = new MyClass() // Heap allocation, using new....
return mc;
}

The above fails, as "escaping reference to local variable" however, this was created using new.... Not understanding what the deal is, this should be a valid heap allocated object, and therefore, why can I not pass this by reference? I don't want this to be a local variable...

So this begs the question: Are Classes (Objects) passed by reference already?

-Brandon

Reply via email to