[英]In C++, Debug assertion failed window pops up & I get vector iterators incompatible error runtime
I've seen some SO links wherein similiar error was seen & was suggessted to use const reference to the vector as they were copying the vector (pass by value) but in my scenario I'm using the same vector (no pass by value). 我已经看到一些SO链接,其中看到了类似的错误,并且在复制矢量(按值传递)时建议使用const引用矢量,但是在我的场景中,我使用的是相同的矢量(不按值传递) 。 But seeing this issue.
但是看到这个问题。 WRT below code, I'm seeing the error
WRT下面的代码,我看到错误
Debug assertion failed window pops up & I get vector iterators incompatible error
调试断言失败窗口弹出并出现向量迭代器不兼容错误
in runtime when the line 在运行时当行
itloop !=-endIter
is hit. 被击中。
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 = table.begin();
auto endIter = tabTypeIterVector[0];
for(auto itloop=startIter; itloop !=-endIter;itloop++)
{
}
}
It looks like you are comparing two iterators that correspond to different vector
objects. 似乎您正在比较对应于不同
vector
对象的两个迭代器。
For example, 例如,
std::vector<int> a(5);
std::vector<int> b(5);
auto iter_a = a.begin();
auto iter_b = b.begin();
Even though iter_a
and iter_b
are of the same type, comparing them is not allowed. 即使
iter_a
和iter_b
是同一类型,也不允许进行比较。 Use of either iter_a == iter_b
or iter_a != iter_b
is cause for undefined behavior. 使用
iter_a == iter_b
或iter_a != iter_b
会导致未定义的行为。
It's not clear from your post why you have the need for comparing the iterators but you'll have to rethink your implementation strategy. 从您的帖子中还不清楚,为什么需要比较迭代器,但是您必须重新考虑实现策略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.