What am I doing wrong ?

Marco Leise Marco.Leise at gmx.de
Wed Apr 25 23:25:55 PDT 2012


Am Sun, 22 Apr 2012 23:47:20 +0200
schrieb "SomeDude" <lovelydear at mailmetrash.com>:

> void main() {
>      auto array = new Foo[10];
> --> for(int i = array.length; i > 1; i--) { array[i].x = i; }
>      writeln();
>      foreach(Foo f; array) { write(f.x);}
> }
> 
> throws core.exception.RangeError at bug(8): Range violation on the 
> line with the arrow.
> 
> What am I doing wrong ?

You could also try:

foreach_reverse(i, ref f; array) { f.x = i; }

-- 
Marco



More information about the Digitalmars-d-learn mailing list