When an element is erased from a std::map, iterators that refer to it are invalidated. Therefore we should advance the iterator before using it to erase the element, and post-increment works just right to do that.Originally Posted by leeor_net
When an element is erased from a std::map, iterators that refer to it are invalidated. Therefore we should advance the iterator before using it to erase the element, and post-increment works just right to do that.Originally Posted by leeor_net
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Ah, I understand now. That makes perfect sense. I knew a bit about invalidating iterators but never thought I had come across it.
Thank you!