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
You can't remove elements from a sequence container while iterating over it — at least not the way you are doing it — because calling erase
invalidates the iterator. You should assign the return value from erase
to the iterator and suppress the increment:
while (interIterator != externIterator->end()){
if (interIterator->getReference() == tmp){
interIterator = externIterator->erase(interIterator);
} else {
++interIterator;
}
}
Also, never use post-increment (i++) when pre-increment (++i) will do.