Friend class

xiaoxiao2021-03-06  40

1. The class also has a friend class, and a friend class can access the private data of the class, and the non-friend class cannot access the private data of the class, which implements the class package.

2. When a class is a friend of another class, the class is called a friend class. All member functions of the friend class are another class of friend functions, and they can access hidden information in another class (including private members and protect members). Friends can explain in another class of public sections or private parts, and the methods are as follows: Friend // Friends class class Note: (1) Friends Can't be inherited . (2) The friend relationship is unidirectional and does not have exchanges. If the class X is the friend of the class y, the class y is not necessarily the class X's friend, and it is necessary to see if there is a corresponding statement in the class. (3) The friend relationship does not have delivery. If the class X is the friend of the class y, the class y is Z 'own, class X is not necessarily a friend of Class Z.

转载请注明原文地址:https://www.9cbs.com/read-53109.html

New Post(0)