April 21, 2004 [BUG] foreach with new | ||||
---|---|---|---|---|
| ||||
//works fine: for( int i = 0; i < 2; ++i ) { children[i] = new Node(); } //this works, until you exit the loop/function //then when you try to access children[0] you get an access violation //as it has been cleaned up. //changing child should change children[0] for example. foreach( Node child; children ) { child = new Node(); } |
April 21, 2004 Re: [BUG] foreach with new | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fabian Mathews | use inout foreach(inout Node child; children) "Fabian Mathews" <Fabian_member@pathlink.com> wrote in message news:c64vuk$29iv$1@digitaldaemon.com... > > //works fine: > for( int i = 0; i < 2; ++i ) > { > children[i] = new Node(); > } > > //this works, until you exit the loop/function > //then when you try to access children[0] you get an access violation > //as it has been cleaned up. > //changing child should change children[0] for example. > foreach( Node child; children ) > { > child = new Node(); > } > > |
Copyright © 1999-2021 by the D Language Foundation