foreach reference to struct variable

Jesse Phillips jessekphillips at gmail.com
Thu Feb 7 21:58:52 PST 2008


On Fri, 08 Feb 2008 00:21:01 -0500, Prashant V wrote:

> Denton Cockburn Wrote:
>> use ref while indexing:
>> 
>> foreach (ref s; structs)
>>    // do something
> 
> Ah that works great! Thanks. Is there anything similar for variables. Eg
> can I go
> 
> int test = 5;
> ref auto test2 = test;
> test++;
> 
> and have the change reflected in test?

You would have to make test2 a pointer.

int test = 5
auto test2 = &test
(*test2)++;



More information about the Digitalmars-d mailing list