I was surprised to discover that this compiles.
class A
{
int i;
public:
A() {}
A(A &a) {i = a.i;}
};
int main(void)
{
A a1;
A a2(a1);
}
That is, the object a2
has access to the private members of the object a1
. Why is this the case i.e. why is this useful? How can this access be restricted, if needed?