如果有一些麻烦找到如何做到这一点,所以我决定触摸并继续解决问题,现在似乎已经有了它。
代码是:
Flight ***Matr = new Flight**[airportCount];
for(int i = 0; i < airportCount; i++){
Matr[i] = new Flight*[airportCount];
for(int j = 0; j < airportCount; j++){
Matr[i][j] = new Flight;
}
}
for(int i = 0; i < airportCount; i++){
for (int j = 1; j < airportCount; j++){
Matr[i][j];
}
delete[] Matr[i];
}
delete[] Matr;
当我尝试删除Matr [0] [0]时,sais分段错误; 耶
我错过了哪些错误?
答案 0 :(得分:2)
为什么不使用矢量?
vector < vector < Flight > > Matr( airportCount,
vector < Flight >( airportCount ) )
答案 1 :(得分:1)
将行Matr[i][j] = new Flight;
更改为Matr[i][j] = new Flight[len];
并将第Matr[i][j];
行更改为delete[] Matr[i][j];