友元

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;
}

运行结果:

 

posted on 2016-03-19 14:37  木鸟飞  阅读(155)  评论(0编辑  收藏  举报

导航