unordered_set non const iterator

后端 未结 5 1292
野趣味
野趣味 2021-01-04 23:39

For testing purposes I created a little unordered_set and tried to iterate over the set. The set holds an own class:

class Student {
private:
    int matrNr;
         


        
5条回答
  •  死守一世寂寞
    2021-01-05 00:13

    unordered_set is a kind of data structure where you cant modify an item without changing its location.

    Non-const iterator is const here 'cause STL does protect you from such an obvious mistake.

    If you want to modify an unordered_set's item you have to remove it and add it again.

提交回复
热议问题