Why does std::set seem to force the use of a const_iterator?

后端 未结 4 1589
花落未央
花落未央 2020-12-18 17:51

Consider the simple program below, which attempts to iterate through the values of a set using NON-const references to the elements in it:

#include 

        
4条回答
  •  青春惊慌失措
    2020-12-18 18:07

    From the cpp reference:

    In a set, the value of an element also identifies it (the value is itself the key, of type T), and each value must be unique. The value of the elements in a set cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.

提交回复
热议问题