//友元类
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
class A
{
public:
A(int x):x(x){}
friend class B;
void show(){cout<<x<<endl;}
private:
int x;
};
class B
{
public:
B(int y,A &K):y(y),K(K){}
void show(){cout<<y<<endl;}
void bianshen();
private:
A K;
int y;
};
inline void B::bianshen()
{
cout<<K.x<<endl;
}
int main()
{
A K(3);
K.show();
B c(2,K);
c.show();
c.bianshen();
}
//友元函数
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
class A
{
public:
A(int x):x(x){}
friend void showw(A &K);
void show(){cout<<x<<endl;}
private:
int x;
};
void showw(A &K)
{
cout<<K.x<<endl;
}
int main()
{
A fnq(22);
fnq.show();
showw(fnq);
}