Does protected inheritance allow the derived class access the private members of its base class?

后端 未结 5 1030
日久生厌
日久生厌 2020-12-28 09:01

I am really confused about private inheritance and protected inheritance.

1) in protected inheritance, the public and protected members become protected members in

5条回答
  •  不知归路
    2020-12-28 09:56

    1) You are correct. No type of inheritance allows access to private members (only friend declarations allow that)

    2) They're "inherited" in the sense that an object of type Derived, when stored in memory, includes all of the data members of Derived and Base, including private members of Base. The private members can't just go away since when methods of Base run on that object, they will need to access Base's private members.

    Also, the names of the private members of Base are technically in scope in Derived's methods, but of course you'll get a compile error if you try to access them.

提交回复
热议问题