Removing item from vector while iterating?

后端 未结 8 2175
小鲜肉
小鲜肉 2020-11-27 15:40

I have a vector that holds items that are either active or inactive. I want the size of this vector to stay small for performance issues, so I want items that have been mark

8条回答
  •  时光说笑
    2020-11-27 16:26

    Removing items from the middle of a vector will invalidate all iterators to that vector, so you cannot do this (update: without resorting to Wilx's suggestion).

    Also, if you're worried about performance, erasing items from the middle of a vector is a bad idea anyway. Perhaps you want to use an std::list?

提交回复
热议问题