int N = 10; int** G; //初始化 G = new int*[N]; for (int i = 0; i < N; i++) G[i] = new int[N]; //删除 for (int i = 0; i < N; i++) delete[] G[i]; delete[] G;
注意数组delete时用delete[ ],否则只能释放数组中第一个元素的空间。
int N = 10; int** G; //初始化 G = new int*[N]; for (int i = 0; i < N; i++) G[i] = new int[N]; //删除 for (int i = 0; i < N; i++) delete[] G[i]; delete[] G;
注意数组delete时用delete[ ],否则只能释放数组中第一个元素的空间。