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??
CodePudding user response:
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 C terminology would translate to private non-static data members. The quote probably is missing context though as well.