怎样动态申请n维数组?
请问怎么动态申请2维数组,n维呢? 我查过书,看不太懂,是不是只有一组下标才能用变量表达式?
float (*cp)[25][10];
cp=new float[10][25][10];
这样申请是什么意思呢?
/**
d1 can be a variable, d2---dn have to be constants.
The reason is that the complier needs to know how much
memory should be allocated.
*/
int d1;
const int d2=5;
...
const int dn=5;
float (*cp)[d2]...[dn];
d1=3;
cp = new float[d1][d2]...[dn];
delete [] cp;
d1=7;
cp = new float[d1][d2]...[dn];
delete [] cp;