您的位置:首页 > 其它

友元

2016-03-19 14:37 197 查看
main.cpp

#include <iostream>
using namespace std;
class Me{
private:
int id;
int money;
friend void test(void);
friend class MyBestFriend;
};
class MyBestFriend{
public:
MyBestFriend(){
Me m;
m.money = 100;
cout << m.money << endl;
}
};
void test(void){
Me m;
m.id = 3;
cout << m.id << endl;
}
int main(){
test();
MyBestFriend mbf;
cout << "letben" << endl;
system("pause");
return 0;
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: