Returning reference: why this works?
Denis Feklushkin
feklushkin.denis at gmail.com
Wed Mar 13 20:57:13 UTC 2019
import std.stdio;
struct S { int x; }
ref S func1(ref S i) // i is reference
{
return i;
}
ref S func2(S i) // i is not reference
{
return func1(i); // Works! Possibility to return reference to
local object i?
//return i; // Error: returning i escapes a reference to
parameter i
}
void main() {
auto ret = func2(S(2));
writeln(ret); // "S(2)"
}
More information about the Digitalmars-d-learn
mailing list