The erase function should take a regular iterator as an argument. To get such an iterator, you can try calling
minheap.erase(std::prev(minheap.end()));
This calls end () to get the iterator to the end, and then returns it one step, using the new C ++ 11 prev function. If you do not have support in C ++ 11, you can write as an alternative
minheap.erase(--minheap.end());
Alternatively, since it seems like you're trying to use a multimap as a mini-heap, did you consider using priority_queue or heap algorithms like push_heap and pop_heap instead?
EDIT . To answer your next question, the reason you get two different values ββis because logically, rbegin points to the last element of the multimap, not one step to it, and the end points are one after the other. One step backup refers to the same element as rbegin, so if you then move rbegin one step forward, it will point to the element one step before the last element.
Hope this helps!
source share