c++友元

来源:互联网 发布:单片机模拟仿真软件 编辑:程序博客网 时间:2024/06/07 05:45

类允许其它类,其它函数访问它的私有成员,友元不是类的成员

class Test{public:    Test(int j) : x(j)    {    }    ~Test()    {    }    friend void print(const Test& test);private:    int x;};void print(const Test& test){    cout << test.x << endl;}


0 0
原创粉丝点击