/*
5. Create three classes. The first class contains private data,
and grants friendship to the entire second class and to a
member function of the third class. In main( ),
demonstrate that all of these work correctly.
*/
#include < iostream >
using namespace std;
// 先声明A,确保C::cfun(A*)可以被正确声明
class A;
// C的定义必须在A的前面,否则就无法friend void C::cfun(A*)
class C {
public :
void cfun(A * );
};
class A {
int a;
public :
friend class B;
friend void C::cfun(A * );
};
class B {
int b;
};
// C::cfun(A*)的定义
void C::cfun (A * t) {
cout << t << endl;
}
5. Create three classes. The first class contains private data,
and grants friendship to the entire second class and to a
member function of the third class. In main( ),
demonstrate that all of these work correctly.
*/
#include < iostream >
using namespace std;
// 先声明A,确保C::cfun(A*)可以被正确声明
class A;
// C的定义必须在A的前面,否则就无法friend void C::cfun(A*)
class C {
public :
void cfun(A * );
};
class A {
int a;
public :
friend class B;
friend void C::cfun(A * );
};
class B {
int b;
};
// C::cfun(A*)的定义
void C::cfun (A * t) {
cout << t << endl;
}