向量迭代器不兼容的错误,用于保存另一个向量的迭代器的向量
Vector iterators incompatible error for a vector holding iterators of another vector
参考前面的SO问题,我纠正了我的错误并将迭代器更改为相同的"向量类型",即
我更换了线路
auto startIter = table.begin((;
跟
自动启动Iter = tabTypeIterVector[0];
在 AccessTableIteratorsVector(( 函数中的 for 循环中。 但是,在代码下方,我仍然收到"调试断言失败,矢量迭代器不兼容错误,当此行在 for 循环中被击中时
itloop !=-endIter
typedef vector<vector<string> tableDataType;
vector<tableDataType::Iterator> tabTypeIterVector;
tableDataType table;
FillRows(vector<string> vstr)
{
table.push_back(vstr);
if(some_condition_satisfied_for_this_row())
{
tableDataType::Iterator rowIT = table.end();
tabTypeIterVector.push_back(rowIT);
}
}
In another function:
AccessTableIteratorsVector()
{
auto startIter = tabTypeIterVector[0];
auto endIter = tabTypeIterVector[1];
for(auto itloop=startIter; itloop !=-endIter;itloop++)
{
}
}
push_back
可能会导致向量中包含的数据重新分配。并且这种重新分配将使向量的所有迭代器无效。取消引用无效迭代器会导致未定义的行为。
对向量的索引将继续保持有效,除非您从向量中删除元素。
相关文章:
- std::向量迭代器和调整大小/保留的奇怪/有趣行为
- 如何取消引用向量迭代器
- Map中的(字符串的)向量迭代器
- C++将向量迭代器转换为索引
- 无法取消引用超出范围的向量迭代器 - 有什么问题?
- 向量迭代器不兼容的错误,用于保存另一个向量的迭代器的向量
- C++向量迭代器nth_element编译错误
- 无法查找值初始化的向量迭代器?
- STD ::向量迭代器类型和允许的操作
- 向量迭代器 < 或 !=
- 向量迭代器在新对象的 push_back() 之后不兼容
- 向量迭代器对于包装器类不可取消引用(没有超出 end() 取消引用)
- C++向量迭代器不是增量的
- 使用向量迭代器的合并矢量
- 向量迭代器不可递增
- 向量迭代器进行循环
- 向量迭代器与c++不兼容
- 向量迭代器不可解引用C++
- C++将向量迭代器与实例进行比较
- 编译错误 ::向量 ::迭代器