Suppose I have the following class:
class Test
{
int num;
public:
Test(int x):num(x){}
Test(const Test &rhs):num(
private
doesn't mean private to the object instance. It means private to that class. An instance of a class T
can access private members of other instances T
. Similarly, a static method in a class T
can access private members of instances of T
.
If private
restricted access to only the individual instance, it would make objects non-copyable, since as you pointed out, the copy constructor would not be able to read data from the original instance.