Can 'iterator' type just subclass 'const_iterator'?

前端 未结 3 1083
谎友^
谎友^ 2021-01-01 19:54

After another question about iterators I\'m having some doubts about custom containers. In my container, iterator is a subclass of const_iterator,

3条回答
  •  我在风中等你
    2021-01-01 20:07

    Yes, this is fine. This is how VC10's implementation of the iterators for vector are structured, for example. See _Vector_iterator and _Vector_const_iterator in .

    By the way, writing iterators is hard. It's worth your time to learn and use the boost::iterator library.

提交回复
热议问题