January 07, 2004 Multi-Dimensional array suggestion | ||||
---|---|---|---|---|
| ||||
I wanted to make a suggestion about multi dimensional array assignments: When I define int[4] array; I can use array[] = 5; which is by definition the same as for (int i=0; i<4; i++) array[i] = 5; But when I define int[4][5] array2; I cannot use array2[][] = 5; because this is the same as for (int i=0; i<5; i++) array2[][i] = 5; I get the error "cannot convert int to int[4]". Wouldn't it be more logical to define array2[][]=5 as for (int i=0; i<4; i++) array[i][] = 5; , which would be the same as for (int i=0; i<4; i++) for (int j=0; j<5; j++) array[i][j] = 5; ? This would make multi-dim array initialising way easier, without having to use loops when the dimension is higher than 1. |
January 07, 2004 Re: Multi-Dimensional array suggestion | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark Arts | That sounds like the right way to do it, but currently none of this stuff is implemented in DMD. Sean "Mark Arts" <Mark_member@pathlink.com> wrote in message news:btgqcf$16hu$1@digitaldaemon.com... > I wanted to make a suggestion about multi dimensional array assignments: > > When I define > int[4] array; > I can use > array[] = 5; > which is by definition the same as > for (int i=0; i<4; i++) > array[i] = 5; > > But when I define > int[4][5] array2; > I cannot use > array2[][] = 5; > because this is the same as > for (int i=0; i<5; i++) > array2[][i] = 5; > I get the error "cannot convert int to int[4]". > > Wouldn't it be more logical to define array2[][]=5 as > for (int i=0; i<4; i++) > array[i][] = 5; > , which would be the same as > for (int i=0; i<4; i++) > for (int j=0; j<5; j++) > array[i][j] = 5; > ? This would make multi-dim array initialising way easier, without having to use > loops when the dimension is higher than 1. |
Copyright © 1999-2021 by the D Language Foundation