C++ map access discards qualifiers (const)

后端 未结 5 695
野性不改
野性不改 2020-12-04 10:05

The following code says that passing the map as const into the operator[] method discards qualifiers:

#include 
#in         


        
5条回答
  •  暖寄归人
    2020-12-04 10:25

    You cannot use operator[] on a map that is const as that method is not const as it allows you to modify the map (you can assign to _map[key]). Try using the find method instead.

提交回复
热议问题