Simple array init question

Graham grahamamacdonald at gmail.com
Sat Apr 7 01:24:21 PDT 2007


Why will array setting work for a 1D array, but not a 2D?  If I enter:
   int[5] buffer;
   buffer[] = 5;

It compiles, but if I enter:
   int[5][5] buffer;
   buffer[][] = 5;

(I tried the variation buffer[] = 5, but that didn't work either.)

It fails to compile (in gdc), with the warning:

   MainLoop.d:56: Error: cannot implicitly convert expression (5) of 
type int to int[5]
   Error: cannot cast int to int[5]
   make: *** [build/MainLoop.o] Error 1

To my untrained eye, it looks like it would like me to pass it an int[5] 
to initialize the array, but that's a bit odd - I'd much rather treat it 
similarly to a 1D array in this case!

Thanks,
graham



More information about the Digitalmars-d mailing list