I\'m working with iterators on C++ and I\'m having some trouble here. It says \"Debug Assertion Failed\" on expression (this->_Has_container()) on line interIterator++. Dist
vector's erase()
returns a new iterator to the next element. All iterators to the erased element and to elements after it become invalidated. Your loop ignores this, however, and continues to use interIterator
.
Your code should look something like this:
if (condition)
interIterator = externIterator->erase(interIterator);
else
++interIterator; // (generally better practice to use pre-increment)