c++ friend
friend functions
A friend function is a function that isn't a member of a class but has access to the class's private and protected members. Friend functions aren't considered class members; they're normal external functions that are given special access privileges.
Class members as friends
A friend class is a class all of whose member functions are friend functions of a class, that is, whose member functions have access to the other class's private and protected members.
Suppose the friend declaration in class B had been:
friend class A;
In that case, all member functions in class A would have been granted friend access to class B. The following code is an example of a friend class:

浙公网安备 33010602011771号