Returning a struct by reference

BCS none at anon.com
Sat Mar 21 09:55:41 PDT 2009


Hello Simon,

> If I add a getter-property that returns the field by value, the
> following instruction "object.position.x = 12;" won't modify the
> position of the object, but will only modify the returned copy of the
> position, right?
> 
> That's actually why I'd like to have a getter that returns the field
> by reference and not by value.
> 


That is correct. Reference returns are on the todo list. For now this Hack 
should work.


struct S { float x; float y; }


class C
{
    S s

    class C_S { void x(float v){ s.x=v; } void y(float v){ s.y=v; } }

    C_S pos() { return new C_S(); }
}





More information about the Digitalmars-d mailing list