4 ms·
The solution is to have the function not return a pointer but return a ref. A ref is a non-owned pointer.
by WalterBright 7y ago
The solution is to have the function not return a pointer but return a ref. A ref is a non-owned pointer.
- e12e 7y agoWould this be similar to passing argument(s) and return pointers/variables to a C function - or similar with assembler, reserving some registers for return values (aka caller manages memory)? But with the (d) compiler helping enforce correctness?
- WalterBright 7y agoNot sure what you mean, but sounds like it is.
- sriram_malhar 7y agoThanks. References work for the iterator example. I am a bit uncomfortable with not being able to move a pointer out of a structure, but it may be a restriction that's worth it; I can't think of a counterexample off the top of my head.