【发布时间】:2016-08-26 10:54:43
【问题描述】:
我有这个向量:
std::vector<int**> vec;
我用大小为size x size 分配给new 的二维矩阵填充这个向量(我检查了保存在向量中的矩阵中的值,它们是正确的)
matrix = new int*[size];
for (int i = 0; i < size; ++i)
matrix[i] = new int[size];
/*here I add some values to the array and save it to the vector
*
*
*/
vec.push_back(matrix);
/* this I do with several matrices
然后我想删除向量中的矩阵并将向量擦除为零长度。
for (int i = 0; i < vec.size(); ++i){
for (int j = 0; j < size; ++j){
delete[] vec[i][j];
delete[] vec[i];
}
}
if (vec.size() > 0)
vec.erase(vec.begin(), vec.end());
删除导致此错误:
double free or corruption (fasttop):
我的代码有什么问题?
【问题讨论】:
-
我不完全理解它,但我发现 this 很有趣,当你想在 c++ 中删除向量的特定列或行时
标签: c++ matrix multidimensional-array vector