Aliasing member's members

Kayomn spam at kayomn.net
Mon Feb 26 21:08:32 UTC 2018


On Monday, 26 February 2018 at 21:04:51 UTC, TheFlyingFiddle 
wrote:
> On Monday, 26 February 2018 at 20:50:35 UTC, Kayomn wrote:
>> [...]
>
> Don't think you can alias member variables directly.
>
> You could do this though:
>
> struct Player {
>     Entity entity;
>
>     ref auto pos() inout { return entity.position; }
> }
>
> Which will give you most of what you want. Although if you want 
> to take the address of pos you have to use
>
> auto addr = &player.pos();

Damn, was hoping to keep my structs as plain old data-structures. 
Thanks for the info, guess I won't be doing this then.


More information about the Digitalmars-d-learn mailing list