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???:
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];
My best code is written with the delete key.
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;
Last edited by manofsteel972; 04-12-2004 at 08:45 AM.
"Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
-- Cowper
Operating Systems=Slackware Linux 9.1,Windows 98/Xp
Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)
You may teach a person from now until doom's day, but that person will only know what he learns himself.
Now I know what doesn't work.
A problem is understood by solving it, not by pondering it.
For a bit of humor check out xkcd web comic http://xkcd.com/235/