64,633
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class base
{
public:
base(int x=1024)
{
a=x;
}
void display()
{
cout <<a <<endl;
}
private:
int a;
friend void display1(base x) //友元函数的定义
{
cout <<"The color of the car is : " <<x.a <<endl;
}
friend istream& operator>>(istream& input, base& str)
{
input>>str.a; //访问私有数据成员
cout <<str.a; //访问私有数据成员
return input;
}
};
void main(void)
{
base mm;
// cin>>mm;
mm.display();
}