How to Declare Friend Classes in C++
In C++, the friend keyword can be used to declare friend classes. Friend classes can access the private and protected members of the class. The syntax for declaring friend classes is as follows:
class A {
friend class B; // B是A的友元类
};
In the example above, class B is declared as a friend class of class A, which means that class B can access the private and protected members of class A. Friend class declarations typically appear within the definition of a class, after the access specifiers of the class.