Home  >  Q&A  >  body text

c++ - map容器的value_type中的key_type为何是const?

map<string, int>::key_type v1;//v1 string
map<string, int>::value_type v2;//v2 pair<const string,int>

为何后者的key_type 是const?而 mapped_type 又不是const?

PHPzPHPz2715 days ago653

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 13:00:11

    Because you cannot change the key of a K/V pair that has been added to the Map, you can only change the value.
    If you want to make changes to the key, you can only delete this one and add a new one.

    reply
    0
  • Cancelreply