While sticking with the theme of having private data members and public methods within all of the objects that I create programming, I am a bit confused about the topic of encapsulation in the context of containing objects within objects.
I have no experience with this, but I have reached a point in my own projects where I want to define objects as the data members of other objects. I sort of think of this has having a "parent object" which can contain one or multiple "child objects". Anyway, if a "child object" is defined as a private data member of a "parent object", how am I suppose to access or change the "child object" without making it publicly accessible? Are objects intended to be private data members of other objects in any context?
I tried making my "child object" protected, not really knowing anything about the concept of protected members/methods (I've only used public and private up until now), but did not have any luck with that. Also, I read on cplusplus.com that there is a "friend" keyword which I believe can be used for the purposes I am describing--although I really don't know--but it was then described as something which was "out of an object-oriented programming methodology" Friendship and inheritance - C++ Documentation. I will read up more on both of these topics, but just figured you guys might know a quick fix for this problem, or would know immediately if I was going down the wrong path entirely. I am quite the beginner, so perhaps I am attempting to do something I shouldn't (ex. not following a best practice).