Reputation: 4197
I was wondering what would be the best way to accomplish something like this...
// Iterating through a list
if ( foo ) {
RemoveBar( it );
}
void RemoveBar( std::list< Type >::iterator it ) {
it = listName.erase( it );
...// Other stuff related to cleaning up the removed iterator
}
I don't think pass by value will work here. Obviously what I want to do is stay in the correct iterator position when I call RemoveBar. Is pass by reference the best alternative?
Upvotes: 0
Views: 3387
Reputation:
Iterators are normally passed by value. I'd make RemoveBar() return the new iterator.
Upvotes: 5