有哪位前辈知道怎样把下面的友元类换成友元函数实现男,请赐教!!
#include <iostream>
using namespace std;
class X
{
public:
friend class Y;
void Set(int i)
{
x = i;
}
void display()
{
cout < < "x = " < < x < < ",y = " < < y < < endl;
}
private:
X a;
private:
int x;
static int y;
};
int X::y = 10;
class Y
{
public:
Y(int i , int j)
{
a.x = i;
X::y = j;
}
void display_X()
{
cout < < "x = " < < a.x < < ".y = " < < X::y < < endl;
}
};
void main()
{
Y c(33 , 44);
c.display_X();
}
[解决办法]
代码编译不过去