Storing a reference
Yuxuan Shui via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Sep 1 12:37:25 PDT 2016
I just figured out how to store a reference:
@safe:
auto x(ref int a) {
struct A {
ref int xa() { return a; }
}
return A();
}
void main() {
import std.stdio;
int b = 10;
auto a = x(b);
a.xa = 20;
writeln(b); //Prints 20
}
I have no idea if this is a right thing to do. Can someone tell
me if this is idiomatic D, and whether there're any catches to
this method or not?
Thanks.
More information about the Digitalmars-d-learn
mailing list