15.2.6 friendship and inheritance
Like other classes, a base class or a derived class can call other classes or functions youyuan. You can use the private and protected data of the metadata class.
The relationship between friends and friends cannot be inherited. The base class's friends do not have special access permissions to the members of the derived class. If the base class is granted a friend relationship, only the base class has special access permissions. The derived class of the base class cannot access the class that grants the friend relationship.
Each class controls the relationship between friends and friends of its own members.
If a derived class wants to grant access from its own members to its friends of the base class, the derived class must explicitly do this: the Friends of the base class do not have special access permissions for the types derived from the base class. Similarly, if both the base class and the derived class need to access another class, the class must grant the access permission to the base class and each derived class.
Class Base {
Friend class Friend;
Friend class ChildFriend;
Private:
Int I;
};
Class Child1: private Base {
Friend class Friend;
Friend class ChildFriend;
Private:
Int j;
};
Class Friend
{
Public:
Int mem (Base B) {return B. I ;}
Int mem (Child1 c) {return c. I + c. j ;}
};
Class ChildFriend: public Friend
{
Public:
Int cmem (Base B) {return B. I ;}
Int cmem (Child1 c) {return c. I + c. j ;}
};
15.2.7 inheritance and static members
If the base class defines static members, there is only one such member in the entire inheritance hierarchy. No matter how many derived classes are derived from the base class, each static member has only one instance.
Static members follow regular access control: if the member is private in the base class, the derived class cannot access it. If you can access a member, you can access the static member either through the base class or through the derived class. Generally, you can use either the scope operator or the DOT or arrow member access operator.
Class Base {
Protected:
Static int I;
};
Class Child: public Base {
Void f (const Child & c)
{
C. I;
Base: I;
Child: I;
I;
}
};
From xufei96's column