Thread overview | |||||
---|---|---|---|---|---|
|
November 10, 2004 3 dimensional Array's | ||||
---|---|---|---|---|
| ||||
Hello, i try to initialize a 3 dimensional Array: this example is OK. static int h[2][3][4] = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16], [17,18,19,20],[21,22,23,24]] ]; not OK. static int[2][3][4] h = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16], [17,18,19,20],[21,22,23,24]] ]; message: Error: too many initializers 4 for array[2] Is the second example wrong? mfg Manfred |
November 10, 2004 Re: 3 dimensional Array's | ||||
---|---|---|---|---|
| ||||
Posted in reply to manfred | (responding to subject)
3 dimensional array is what? Or to what possession of a 3 dimensional array do you refer?
manfred wrote:
<snip>
> not OK. static int[2][3][4] h = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16],
> [17,18,19,20],[21,22,23,24]] ];
>
> message: Error: too many initializers 4 for array[2]
>
> Is the second example wrong?
Yes. When the array dimensions are attached to the type rather than the variable, they go in reverse order. That is, int[2][3][4] is an array of 4 int[2][3]s.
You therefore want
static int[4][3][2] h = [
[[1,2,3,4], [5,6,7,8], [9,10,11,12]],
[[13,14,15,16], [17,18,19,20], [21,22,23,24]]
];
Stewart.
|
November 10, 2004 Re: 3 dimensional Array's | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Thank you. In article <cmt14a$1oa8$1@digitaldaemon.com>, Stewart Gordon says... > >(responding to subject) > >3 dimensional array is what? Or to what possession of a 3 dimensional array do you refer? > >manfred wrote: <snip> >> not OK. >> static int[2][3][4] h = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16], >> [17,18,19,20],[21,22,23,24]] ]; >> >> message: >> Error: too many initializers 4 for array[2] >> >> Is the second example wrong? > >Yes. When the array dimensions are attached to the type rather than the variable, they go in reverse order. That is, int[2][3][4] is an array of 4 int[2][3]s. > >You therefore want > > static int[4][3][2] h = [ > [[1,2,3,4], [5,6,7,8], [9,10,11,12]], > [[13,14,15,16], [17,18,19,20], [21,22,23,24]] > ]; > >Stewart. |
Copyright © 1999-2021 by the D Language Foundation