L
Larry Lindsey
Wonder said:For compiler g++ on Linux, it doesn't work if I use
int **data = new int[m][n];
Can I new an array of int* first, and new an one-dimension array for the
first int*,
then use a loop to make every int* point to the right position?
int **data = new int*[m];
data[0] = new int[m*n];
for(i = 1; i < m; i++)
data = data[0] + i * n;
It should works, however, it failed in my MPI program.
Could anyone give me a better method? Thanks.
Use pointers. C++ requires you to instantiate arrays with const values. So
instead:
int **data = (int**)malloc(m*sizeof(int*));
for (i=0;i<m;i++)
(*data+i)=(int*)malloc(n*sizeof(int));
That would be my take. This will work, but there will probably be better
ways of doing it.
--Larry