Step 4 of 6
Review: modifying while iterating
Another classic: changing a container while looping over it.
- erasing index
ishifts the next element into positioni, and theni++skips it push_backduring a range-for can reallocate, invalidating the loop's hidden iterators- a reference taken before a
push_backcan dangle afterwards
Your turn: this pull request enforces bans and fills the roster back up with substitutes. Fix it so that every banned player is removed (including when two are adjacent), one substitute is added per removed player, and captain returns the right name. There are three bugs.
Previous: Review: leaks on the error path Next: Review: integer math