Give access to encapsulated container

后端 未结 6 1231
借酒劲吻你
借酒劲吻你 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:20

    Off course, the simplest is this :

    class X {
      public:
        typedef std::list Container;
    
        Container m_container;
    };
    

    but that makes your class X obsolete.

    Other then that, if you really like your class, then add next methods :

    Container::const_iterator ElementBegin() const;
    Container::const_iterator ElementEnd() const;
    int size() const;
    

提交回复
热议问题