G
Gerald
There are several ways to build 2D array in C++.
Usually I do it using following code:
// ========================================
int rows = 10, columns = 10;
int *array1d = new int[rows*columns];
int (*array2d)[columns] = reinterpret_cast<int (*)[columns]>(array1d);
/* Now we can use array2d like this - array2d[j] */
// ========================================
The key statement is
int (*array2d)[columns] = reinterpret_cast<int (*)
[columns]>(array1d).
I wonder whether it complies with C++ spec and how it is supposed to
work.
Thanks
Gerald
Usually I do it using following code:
// ========================================
int rows = 10, columns = 10;
int *array1d = new int[rows*columns];
int (*array2d)[columns] = reinterpret_cast<int (*)[columns]>(array1d);
/* Now we can use array2d like this - array2d[j] */
// ========================================
The key statement is
int (*array2d)[columns] = reinterpret_cast<int (*)
[columns]>(array1d).
I wonder whether it complies with C++ spec and how it is supposed to
work.
Thanks
Gerald