Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does private inheritance actually create a base-class object in the derived class?

In C++ Primer Plus p.797,

Containment adds an object to a class as a named member object, whereas private inheritance adds an object to a class as an unnamed inherited object.

I wonder if "private inheritance actually create a base-class object in the derived class" as this book said,
Or is it just a conceptual explanation??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The statement is basically correct, but requires some corrections in the C++ terminology if it is taken strictly. (However, especially when the point is to explain OOP concepts, this terminology is often not used strictly or even conflicts with OOP terminology.)

It is not the class which contains a member object or an inherited object. It is each object of the class type which contains a member subobject or a base class subobject. On the other hand the class itself has members and base classes corresponding to these subobjects.

It is also not clear to me why private is of any relevance here. It doesn’t affect the statement at all. As mentioned under this answer it might just be meant to contrast the "containment" concept which I guess in the C++ language would translate to private non-static data members. The quote probably is missing context though as well.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading