WHY does this code not compile???:
Thanks for your helpCode:field_origin = new u8[field_size*6][field_size*10];
Printable View
WHY does this code not compile???:
Thanks for your helpCode:field_origin = new u8[field_size*6][field_size*10];
>WHY does this code not compile???
Sadly, you can't do what you're trying to do. To simulate a two dimensional array, you need to create an array of pointers and then for each pointer, create an array of T:
Or you could save yourself some calls to new:Code:int **a = new int*[10];
for ( int i = 0; i < 10; i++ )
a[i] = new int[10];
But that isn't as handy when it comes to syntactic sugar and resizing.Code:int *a = new int[10 * 10];
At least this works in MS Visual C++ if you initialize the pointer to the same type as the 2 d array it will accept it.
U8 (*field_origin)[field_size*10]; will create a pointer that is the same type as your array. field_size must be a constant though for it to work. I think U8 is equal to data type _int64 anyway here is the code i got to compile.
Code:const int field_size=5;
_int64(*field_origin)[field_size*10]=new _int64[field_size*6][field_size*10];
field_origin[0][0]=20;
int number=field_origin[0][0];
cout<<number;
delete [] field_origin;