简体   繁体   中英

Insertion in a map

我有一张机票和行李的地图,每张机票必须是唯一的,并且必须对应地图上的一个位置,是否可以只更改行李(m_bagage->second)而不更改密钥?

std::unordered_map<Ticket, bagage> m_consigne;

You cannot change keys in a map, they are const . Moreover keys in maps are unique. To change the value of an existing entry, given the key you can do

std::unordered_map<Ticket, bagage> m_consigne;
// add some entries
bagage b;
Ticket t;
m_consigne[t] = b;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM