Is there an easy way to convert an instance of type int[n][n]
to int**
?
For example, the code
void foo(int** arr) {
// ...
}
int X[10][10];
memset(X,0,10*10*sizeof(int));
foo(X); // error: cannot initialize a parameter of type 'int **' with an lvalue of type 'int [10][10]'
An easy workaround is, of course, to have
int** X=new int*[10];
for (int i=0;i<10;++i) X[i]=new int[10];
but this somewhat counters the idea that in C++ arrays are just pointers (which the 1-dim arrays certainly are).