Insertion in a map

Viewed 28

I have a map of ticket and baggage, each ticket must be unique and must correspond to a position on the map is it possible to change only the baggage (m_bagage-> second) without changing the key?

std::unordered_map<Ticket, bagage> m_consigne;

1 Answers

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;
Related