Difference between private, public, and protected inheritance

后端 未结 16 1835
灰色年华
灰色年华 2020-11-21 06:15

What is the difference between public, private, and protected inheritance in C++?

16条回答
  •  眼角桃花
    2020-11-21 06:49

    Private:

    The private members of a base class can only be accessed by members of that base class .

    Public:

    The public members of a base class can be accessed by members of that base class, members of its derived class as well as the members which are outside the base class and derived class.

    Protected:

    The protected members of a base class can be accessed by members of base class as well as members of its derived class.


    In short:

    private: base

    protected: base + derived

    public: base + derived + any other member

提交回复
热议问题