KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've got code that looks like this: for (std::list<item*>::iterator i = items.begin(); i != items.end(); i++) { bool isActive = (*i)->update(); //if (!isActive) // items.remove(*i); //else other_code_involving(*i); } items.remove_if(CheckItemNotActive); I'd like remove inactive items immediately after update them, in order to avoid walking the list again. But if I add the commented-out lines, I get an error when I get to i++ : "List iterator not incrementable". I tried some alternates which didn't increment in the for statement, but I couldn't get anything to work. What's the best way to remove items as you are walking a std::list?
Tags (comma-separated)
Save Edits
Cancel