Strange behavior using array of structures

Orfeo orfeo.davia at gmail.com
Wed Apr 4 12:03:52 UTC 2018


On Wednesday, 4 April 2018 at 10:09:41 UTC, sarn wrote:
> On Wednesday, 4 April 2018 at 10:00:18 UTC, Orfeo wrote:
>>       foreach (l; log) {
>>          l.run;
>>       }
>
> Try making this "foreach (ref l; log) {".
>
> Structs are value types in D, so by default they're copied when 
> you assign them to another variable (in this case l).  That 
> means run() is modifying a copy that gets thrown away each 
> time.  "ref l" makes l into a reference to the original struct 
> instance.

Great!! thank you very much


More information about the Digitalmars-d-learn mailing list