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). But seeing this issue. WRT below code, I'm seeing the error
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.
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. Use of either iter_a == iter_b
or iter_a != iter_b
is cause for undefined behavior.
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.