#Reverse Iterator getting invalid upon using erase() on multiset

12 messages · Page 1 of 1 (latest)

languid hound
#

In the image, I have a multiset and ritr is a reverse iterator. So ritr.base() is a regular iterator which will point at 4. Now if I execute multisetName.erase(ritr.base()) , this is invalidating my ritr iterator as well. What's the work-around for this so that I can keep ritr reverse iterator validated....?

lofty steepleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

dusky flame
#

you need to get the next iterator before you erase. You can post increment your ritr and then erase from the map (ritr.base())then reassign again. Or you can get the next valid itr with the erase function. However ritr.base() is not pointing to 4 though...

languid hound
dusky flame
#

oh wait

#

its multiset

#

nvm

#

but wait

#

how did you constructor this ritr? ritr.base() returns the iterator from the iterator that it was constructed from. Which is just its forward iterator