re-creating C++'s reference bahavior

BCS ao at pathlink.com
Tue Apr 17 09:04:42 PDT 2007


Reply to swiftcoder - Tristam MacDonald,

> I am fairly new to D, from a C++ background, and I am having a hard
> time coming up with a sensible way to deal with what is a fairly
> trivial example in C++:
> 
[...]
> Vector3f v = n.position();

If I'm reading you correctly, then the problem is that in this line you want 
value semantics and are getting references semantics.

One solution would be to make Vector3f a struct and have .position return 
a pointer to it. In D, pointers to structs and structs are almost identical 
from a syntax standpoint (no . vs ->) Then when you want value semantics 
you would use *n.position().




More information about the Digitalmars-d-learn mailing list