digitalmars.D - 3 dimensional Array's
- manfred (12/12) Nov 10 2004 Hello,
- Stewart Gordon (14/22) Nov 10 2004 (responding to subject)
- manfred (2/31) Nov 10 2004
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
Nov 10 2004
(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.
Nov 10 2004
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.
Nov 10 2004