So I have a list class AnimalCollection which inherits from list<Animal>.
Now I am implementing a method called removeById(int id) which removes certain item in the collection that matches the specified id from the parameter.
My current implementation is below:
void AnimalCollection::removeById(int id)
{
for (auto it = this->begin(); it != this->end(); it++)
{
if (it->id == id)
this->remove((Animal)it);
}
}
Now, on line 6 of my code, it's obvious that it's unwise to convert an iterator to the type that is currently being iterated.
The point is, I want to get the current item being iterated by the iterator it.
Anyone who has idea on how to do it?