Declare reference to variable ?

Namespace rswhite4 at googlemail.com
Mon Jul 29 14:22:45 PDT 2013


On Monday, 29 July 2013 at 21:13:54 UTC, Temtaime wrote:
> I have a long named variable in a struct.
>
> For example let's name that longnamedstruct.longnamedmember
>
> I need to use that variable in many places of the code and i 
> cannot create the copy of it.
>
> In c++ i can
> auto &v = longnamedstruct.longnamedmember;
>
> Now i can use v anywhere.
> Why i cannot declare reference in D ? Or can i ?
>
> I can make pointer to that, but it is workaround and it's need 
> to use variable dereferencing by * operator.

You can use alias:
alias v = longnamedstruct.longnamedmember;


More information about the Digitalmars-d-learn mailing list