Help with multi-dimentional array

BCS ao at pathlink.com
Wed Jul 9 15:31:35 PDT 2008


Reply to Era,

> Koroskin Denis Wrote:
> 
>> No, you create *an array*, not objects of concrete type. Thus, no
>> constructor is called and an array contains a butch of uninitialized
>> class  references. And since no ctor is called, you can't pass any
>> ctor  parameters right there.
>> 
>> So you still need a loop to initialize the array properly.
>> 
> I see. so after i do the = new xyz[][](left,right), and i wanted to
> fill in x,y,z i'd have to
> 
> // this(x,y,z){} //still this constructor
> 
> z=100;
> for(int x=0; x<left; x++)
> for (int y=0; y<right; y++)
> xyz[x][y] = new xyz(x,y,z)

or the slightly nicer/neater version

z=100;
foreach(x, arr; xyz)
foreach (y, ref v in arr)
v = new xyz(x,y,z);

// I might have got x and y backwards




More information about the Digitalmars-d-learn mailing list