首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

有哪位前辈知道怎样把下面的友元类换成友元函数实现男,请赐教!该如何处理

2012-03-01 
有哪位前辈知道怎样把下面的友元类换成友元函数实现男,请赐教!!#includeiostreamusingnamespacestdclas

有哪位前辈知道怎样把下面的友元类换成友元函数实现男,请赐教!!
#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();
}


[解决办法]
代码编译不过去

热点排行