simendsjo wrote:
The spec is very short here, and the example doesn't give me much..
// I thought "allows functinos to return by reference" meant it could
return local variables..
ref int* ptr() {
auto p = new int;
*p = 12;
return p; // Error: escaping local variable
}
For free functions, it's useful for returning references to module or
global scope variables. Though what the use-case for that would be, I
don't know off the top of my head. In C++, it's a common idiom for class
methods to return references, rather than pointers, to class members in
certain situations.