Difference between private, public, and protected inheritance

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

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

16条回答
  •  感动是毒
    2020-11-21 06:30

    I have tried explaining inheritance using a picture below.

    The main gist is that the private members of parent class are never directly accessible from derived/child class but you can use parent class's member function to access the private members of parent class. Private variables are always present in derived class but it cannot be accessed by derived class. Its like its their but you cannot see with your own eyes but if you ask someone form the parent class then he can describe it to you.

提交回复
热议问题