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

后端 未结 5 1024
日久生厌
日久生厌 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:57

    1a) Protected inheritance means the "child" can access everything it could in public inheritance, but others using that object can only see the public interface to the child, anything in it's parent is hidden.

    1b) Private inheritance results in all public functions of a class being inherited as private functions - meaning they can not be called from the child or accessed from a client of your object.

    2) Private members are inherited because methods in the base class might need them to operate on.

提交回复
热议问题