#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);
}
我有一個Map包含兩個條目,也是兩個迭代器指向相同的條目。 使用Iterator1擦除地圖中的一個條目。刪除後仍然Iterator1和Iterator2保持值。std :: map多個迭代器,刪除和它的值
問題
- 是迭代器指向地圖(紅黑樹)的節點
- 是迭代器應對無論是從節點鍵和價值,同時它迭代?因此,即使在從地圖中刪除條目後,它也會保留該值。