Original Post
It is said in the end that, although a class inherits the private members from it's base, it cannot access them. Then it proceeds with the following example: I understand that class A can access a private member of class B but my question is: why? Doesen't it breaks the idea o private a little bit? Extrapolating from this, let's say we have a recursive class, something like: Whould that also be possible? I mean, it compiled fine, but I didn't tried to actually call the function.
class A
{
int x;
static void F(B b) {
b.x = 1; // Ok
}
}
class B: A
{
static void F(B b) {
b.x = 1; // Error, x not accessible
}
}
class A
{
int x;
A some_member;
void F() { //I removed the static, because he is accessing a non-static member.
some_member.x = 1; // Ok?
}
}