December 05, 2006 How to initialize an array like int[][] | ||||
---|---|---|---|---|
| ||||
In dmd/html/d/ctod.html, I see this: int[2][3] b = [ [2,3], [6,5], [3,4] ]; However, when I put it into main(), I can't compile it using DMD 0.175 . To compile it successfully, I must change it to: static int[2][3] b = [ [2,3], [6,5], [3,4] ]; But how this happens. Thans for any help! |
December 06, 2006 Re: How to initialize an array like int[][] | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhang | Remember that you're doing loading a dynamic array, and not a static that needs the static keyword. // InitDynArray.d // WinXP SP2, dmd v0.176 import std.stdio; int main() { //int[2][3] b = [ [2,3], [6,5], [3,4] ]; int[][] b = [ [2,3], [6,5], [3,4] ]; for (int x = 0; x < 3; x++) for(int y = 0; y < 2; y++) writefln("b[%d][%d]=%d", x, y, b[x][y]); return 0; } Output: --------- C:\dmd>dmd initdynarray.d C:\dmd\bin\..\..\dm\bin\link.exe initdynarray,,,user32+kernel32/noi; C:\dmd>initdynarray b[0][0]=2 b[0][1]=3 b[1][0]=6 b[1][1]=5 b[2][0]=3 b[2][1]=4 C:\dmd> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html "zhang" <zxpmyth@yahoo.com.cn> wrote in message news:20061205235820.C47D.ZXPMYTH@yahoo.com.cn... > In dmd/html/d/ctod.html, I see this: > int[2][3] b = [ [2,3], [6,5], [3,4] ]; > > However, when I put it into main(), I can't compile it using DMD 0.175 . > To compile it successfully, I must change it to: > static int[2][3] b = [ [2,3], [6,5], [3,4] ]; > > But how this happens. Thans for any help! > |
Copyright © 1999-2021 by the D Language Foundation