在map中,第一维的索引建立之后就不能再变了,有时候我们确实需要改变它的值,这时可以使用const_cast<>,示例如下:
struct AA{
int key;
int value;
bool operator < (const AA& a) const { return key < a.key; }
};
int main(){
std::map<AA, int> mp;
AA t;
t.key = 1;
t.value = 1;
mp[t] = 1;
std::map<AA, int>::iterator iter = mp.find(t);
printf("%d %d %d\n", iter->first.key, iter->first.value, iter->second++ );
AA& a = const_cast< AA& >(iter->first);
a.value = 6;
printf("%d %d %d\n", iter->first.key, iter->first.value, iter->second);
return 0;
}