友员问题
#include <iostream>using namespace std;
class beta; //前向声明
class alpha
{
private:
int a_data;
public:
alpha() {a_data = 10;}
void display(beta);
};
class beta
{
private:
int b_data;
public:
beta() {b_data = 20; }
friend void alpha::display(beta bb);
// alpha类的成员函数为beta类的友元函数
};
void alpha::display(beta bb)
{
cout<<"\n data of beta ="<<bb.b_data;
cout<<"\n data of alpha ="<<a_data;
}
int main(){
alpha a1;
beta b1;
a1.display(b1);
}
为什么bb.b_data无法变成b_data,我想他是BETA的成员函数,就应该有法,但为什么不行呢???