请问为什么在main函数里,为什么b.g(a)里不能写成b.g(i)?
代码如下:
#include <iostream>
using namespace std;
class X;
class Y {
public:
void g(X& p);
};
class Z {
public:
void f(X& p);
};
class X {
private:
int i;
public:
X(int i_)
{
i = i_;
cout << "i的原值为:" << endl;
}
friend class Z;
friend void Y::g(X& p);
friend void h(X& p);
void show();
};
void Y::g(X& p) {
p.i++;
}
void h(X& p) {
p.i += 10;
}
void Z::f(X& p) {
p.i += 5;
}
void X::show() {
cout << i << endl;
}
int main() {
int i;
cout << "请输入i的值:" << endl;
cin >> i;
X a(i);
a.show();
Y b;
b.g(a);
a.show();
Z z;
z.f(a);
a.show();
h;
h(a);
a.show();
return 0;
}