Correct. But you can hack into it with a single int * and knowledge of how the memory is aligned. Its ugly, but I don't know of another way due to the limitations of the language syntax.
you can make a function, pass it bar[0] reshaped as an int*, and access that [23] or whatever location...
you must know its dimensions and how to convert from 1d back to 2d etc, but it does work. This may be one of those 'undefined but works on all compilers' things.
... a hideous example of this sort of mess (this is why vectors and single dimensional pointers are preferable ...)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
void foo( int *x)
{
x[23] = 1000000;
}
int main()
{
int z[10][10];
int i,j;
for(i = 0; i < 10; i++)
for(j = 0; j < 10; j++)
z[i][j] = 1*10+j;
foo(z[0]);
for(i = 0; i < 10; i++)
for(j = 0; j < 10; j++)
cout << z[i][j] << endl;
return 0;
}
|
I would not actually do this, but then again, I would not actually use a 2-d array either.
I think you can also abuse the cast syntax to force the single pointer back to a double * and index into it normally if you really want to.
Of course this is left over from dealing with C. C++ it may be best to just overload the function headers ... regardless, its a miss on the language syntax since it isnt necessary to feed it the hard coded sizes, nor should it be.