int **a = new int[5][6],这个根本编译不过去吧。
如果你想new一个二维数组出来,应该这样:
int** a= new int*[5];
for (int i = 0; i < 5; ++i)
{
a[i] = new int[6];
}
delete的时候,反过来就行了:
for (int i = 0; i < 5; ++i)
{
delete[] a[i];
}
delete[] a;
三维数组,与此相同,举例如下:
int*** a= new int**[5];
for (int i = 0; i < 5; ++i)
{
a[i] = new int*[6];
for (int j = 0; j < 6; ++j)
{
a[i][j] = new int[7];
}
}
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 6; ++j)
{
delete[] a[i][j];
}
delete[] a[i];
}
delete[] a;