#include <stdio.h>
#include <iostream>
#include <map>
#include <string>
#include <stdlib.h>
using namespace std;
class Fix
{
};
int main()
{
map<int, Fix *> m;
Fix * f = new Fix();
m.insert( make_pair( 2, f) );
m.insert( make_pair( 3, f) );
map<int, Fix *>::iterator it = m.find(2);
map<int, Fix *>::iterator it1 = m.find(2);
m.erase(it);
// Will Create problem
// m.erase(it1);
// Still value is there
// So from the map node, iterator copy its value ?
printf("%d\n", it->first);
printf("%d\n", it1->first);
}
I have a Map contains two entries, also two iterators pointing to same entry. Erased one entry from map using Iterator1. Post deletion still Iterator1 and Iterator2 hold value.
Questions
- Is Iterator is pointing to the node of Map ( Red Black Tree)
- Is Iterator is coping both key and value from the node while it is iterating ? Because of this it holds the value even after entry is deleted from the map.