C++ iterator and const_iterator problem for own container class

后端 未结 3 2090
猫巷女王i
猫巷女王i 2020-12-09 05:10

I\'m writing an own container class and have run into a problem I can\'t get my head around. Here\'s the bare-bone sample that shows the problem.

It consists of a con

3条回答
  •  不思量自难忘°
    2020-12-09 05:49

    In containers iterator type must be convertible to const_iterator. It is needed for the cases where you iterate through a mutable container using a non-mutable (const) iterator as this makes perfect sense. In your case myc is mutable (non-const), but you create a const iterator on that.

提交回复
热议问题