C++的问题:将成员函数用作友元的一个程序,对最后一个输出结果不理解
#include <iostream>using namespace std;
class Two;
class One{
int x;
public:
One(int a){x=a;}
int Getx(){return x;}
void func(Two&);
};
class Two{
int y;
public:
Two(int b){y=b;}
int Gety(){return y;}
friend void One::func(Two&);
};
void One::func(Two& r)
{r.y=x;}
void main(){
One obj1(5);
Two obj2(8);
cout<<obj1.Getx()<<" "<<obj2.Gety()<<endl;
obj1.func(obj2);
cout<<obj1.Getx()<<" "<<obj2.Gety()<<endl;
}
输出结果是:5 8
5 5
对于这个结果,5 8是可以理解的,可是没法理解5 5的输出结果。还是书没看透,哪位前辈可以帮我指点一下。谢谢!