Give access to encapsulated container

后端 未结 6 1283
借酒劲吻你
借酒劲吻你 2021-01-13 02:38
class X {
  public:
    typedef std::list Container;

    // (1)
    const Container& GetElements() const;

    // (2)
    Container::iterator Element         


        
6条回答
  •  误落风尘
    2021-01-13 03:36

    2 and 3 really aren't distinct options. However, 3 as written is pretty much useless. No STL algorithm will use CustomIterator::next. For STL compatibility, you'd write:

    // mix of 2 and 3
    CustomIterator begin();
    CustomIterator end();
    

    and give CustomIterator the standard operator++ and operator*

提交回复
热议问题