分类: C/C++
2009-05-07 19:56:13
二维数组new小结
1.
A (*ga)[n] = new A[m][n];
...
delete []ga;
缺点:n必须是已知
优点:调用直观,连续储存,程序简洁(经过测试,析构函数能正确调用)
2. A** ga = new A*[m];
for(int i = 0; i < m; i++)
ga[i] = new A[n];
...
for(int i = 0; i < m; i++)
delete []ga[i];
delete []ga;
缺点:非连续储存,程序烦琐,ga为A**类型
优点:调用直观,n可以不是已知
3. A* ga = new A[m*n];
...
delete []ga;
缺点:调用不够直观
优点:连续储存,n可以不是已知
4. vector