Why is this vector iterator not incrementable?

前端 未结 8 1190
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 10:41

I\'m trying to delete the vector\'s content and I\'m getting an error - vector iterator is not incrementable, why is that?

This is my destructor:

C         


        
8条回答
  •  無奈伤痛
    2020-12-13 10:49

    The problem is that you are trying to use an iterator while using the erase() function. erase(), push_back(), insert(), and other modifying functions invalidate iterators in STL.

    Just use the clear() function:

    City::~City()
    {
        m_basesVector.clear();
    }  
    

提交回复
热议问题