所以,我偶然发现的是:
std::map<double, int> map1;
std::map<double, int> map2;
map1[2.5] = 11;
map1[3.5] = 12;
map2[2.5] = 21;
map2[3.5] = 22;
std::map<double, int>::iterator iterMap1 = map1.find(2.5);
//I will now try to erase a key/value pair in map2 with an iterator
//that points to map1. This is bad/wrong. But I am surprised
//this is allowed.
map2.erase(iterMap1);
//what do you think would be printed?
print(map1);
print(map2);
有人可以解释这种行为吗?我认为这不应该被允许。
我得到的输出是:
Map1
2.5 11
Map2
2.5 21
3.5 22
这对我来说没有意义。谢谢。