Hello, the code below (which was very kindly modified by somebody on-line )erases the objects contained in a list tempList that meet the 'if' condition. It works fine , but i don't understand how?. It basically steps through the for..next loop. I think the 'else' statement is confusing me.
void KillMutants2(list < mutantType> &tempList)
std::list < mutantType> ::iterator i;
for (auto it=tempList.begin();it!=tempList.end();)
if (it->getAge()==3 && it->IsMutant())
cout << "\nBunny " << it->getName() << " has died of old age";
Use of the iterator is very similar in concept to normal integers.
erase() returns an iterator to the item in the list that follows the item that was deleted. If nothing needs to be deleted than the else statement on line 13 take affect and the iterator is incremented.