Re: Resizing array of classes

2012-10-19 Thread monarch_dodra
On Friday, 19 October 2012 at 13:41:53 UTC, Jacob Carlborg wrote: On 2012-10-19 11:42, Marco Leise wrote: When you extend the length of an array, it is filled with the static .init value for the type, which is null here. I think you'll have to create the objects manually. foreach (ref foo; a)

Re: Resizing array of classes

2012-10-19 Thread Jacob Carlborg
On 2012-10-19 11:42, Marco Leise wrote: When you extend the length of an array, it is filled with the static .init value for the type, which is null here. I think you'll have to create the objects manually. foreach (ref foo; a) foo = new Foo; Is this possible: a[] = new Foo; ? -- /Jacob Ca

Re: Resizing array of classes

2012-10-19 Thread Artur Skawina
On 10/19/12 11:09, m0rph wrote: > Suppose I have a dynamic array of classes, something like: > > class Foo { > int value; > } > > Foo[] a; > > Now I want to resize it and initialize new items with default values, so I do > following: > > a.length = 10; > a[0].value = 1; > > And by executi

Re: Resizing array of classes

2012-10-19 Thread Marco Leise
Am Fri, 19 Oct 2012 11:09:42 +0200 schrieb "m0rph" : > Suppose I have a dynamic array of classes, something like: > > class Foo { > int value; > } > > Foo[] a; > > Now I want to resize it and initialize new items with default > values, so I do following: > > a.length = 10; > a[0].value =

Resizing array of classes

2012-10-19 Thread m0rph
Suppose I have a dynamic array of classes, something like: class Foo { int value; } Foo[] a; Now I want to resize it and initialize new items with default values, so I do following: a.length = 10; a[0].value = 1; And by executing the last line of code I've got a segmentation fault. App