Difference between private, public, and protected inheritance

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

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

16条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 06:32

    If you inherit publicly from another class, everybody knows you are inheriting and you can be used polymorphically by anyone through a base class pointer.

    If you inherit protectedly only your children classes will be able to use you polymorphically.

    If you inherit privately only yourself will be able to execute parent class methods.

    Which basically symbolizes the knowledge the rest of the classes have about your relationship with your parent class

提交回复
热议问题