好基友

#include<iostream>
using namespace std;

class building
{
    //告诉编译器 goodgay全局变量 是buliding的好朋友,可以访问私有内容
    friend void goodgay(building* B);
public:
    building()
    {
        this->n_name = "客厅";
        this->N_name = "卧室";
    }
    string n_name;
private:
    string N_name;
};

void goodgay(building* B)
{
    cout << "你的好基友正在访问:" << B->n_name << endl;
    cout << "你的好基友正在访问:" << B->N_name << endl;
}

void test()
{
    building a;
    goodgay(&a);
}

int main(void)
{
    test();
    return 0;
}

 

posted @ 2021-01-10 16:54  loliconsk  阅读(386)  评论(0)    收藏  举报