Help with multi-dimentional array

Koroskin Denis 2korden+dmd at gmail.com
Wed Jul 9 15:14:03 PDT 2008


On Thu, 10 Jul 2008 01:58:46 +0400, Era Scarecrow <rtcvb32 at yahoo.com>  
wrote:

> Jarrett Billingsley Wrote:
>
>> "Era Scarecrow" <rtcvb32 at yahoo.com> wrote in message
>> news:g538vm$2391$1 at digitalmars.com...
>>
>> >        abc = new xyz[left][right];    //error needs a const
>>
>> Just a little weirdness.  When you write "new xyz[5]" it's actually  
>> sugar
>> for "new xyz[](5)".  Think of it like a class -- "new Type(Params)".
>>
>> For multidimensional arrays, just write
>>
>> abc = new xyz[][](left, right);
>>
>> It does exactly the same as the much more verbose loop. :)
>>
>
>  Ah i see. I don't remember this being covered in any of the books i was  
> reading, and having to go through several loops not only looks ugly; but  
> invites bugs.
>
>  So if i had a 3-dimentional array, i'd assume i'd have to "= new  
> xyz[][][](a,b,c)?" and so on and so forth?
>
>  Then, the question comes up next. If i actually pass a parameter to a  
> class's constructor, would it be....
>
> class xyz{
>     this(x,y,z){} //three dimentional points
> }
>
> //make two dimentional array taking a 3-dimentional location
>
>  abc = new xyz[][](left, right)(x,y,z);   //is this right??
>
>  Era

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.


More information about the Digitalmars-d-learn mailing list