Accessing a private field from one class to another not related to the former class in C++ (OOP)
Accessing a private field from one class to another not related to the former class in C++ (OOP) I have 2 classes - A and B . Class A has a member list<int> and a method addData() that adds a number to this list. The second class B has a function displayContent() - it iterates through the list of the class A and prints its content (the added numbers). The problem I face is that I cannot access the private (cannot be changed to public) field list of class A from the newly instantiated object (from class B ). I would like to ask how can this be achieved with getters/setters , or a copy constructor ? A and B A list<int> addData() B displayContent() A private list A B getters/setters copy constructor //identifier 'a' is undefined? - you didn't pass an instance of A as a variable and B is not a child of A, so how can a be defined? – user4035 Jun 30 at 7:39 ...