Serializable Person类定义了一个它自己的友元,如清单1所示。
Consider a Serializable Person class that defines a friend of its own, as shown in Listing 1.
名为spacefriend的友元函数,它是space类的友元,它的参数是类对象,输出类对象的x变量的值。
A friend function named spacefriend, which is a friend of class space, and which takes the class object as an argument and prints the value of its variable x.
为了访问一个用户定义的类里的私有数据,你必须声明全局函数为友元函数,并且在类中定义。
But to be able to reach any private data within a user defined class you have to declare the global function as a friend within the definition of the class.
友元函数用来访问类的非公有成员。友元函数不是类的成员函数。
A friend function is used for accessing the non-public members of a class.
友元函数用来访问类的非公有成员。友元函数不是类的成员函数。
A friend function is used for accessing the non-public members of a class.
应用推荐