小编Guc*_*112的帖子

私人功能作为其他班级的朋友

我有一个用C++编写的以下代码:

#include <iostream>

using namespace std;

class Window;
class Level
{
    int level;
    int get(Window& w);
public:
    Level(void): level(3) {}
    void show(Window& w);
};

void Level::show(Window& w)
{
    cout << get(w) << endl;
}

class Item
{
    static const int item = 8;
};

class Window
{
    friend int Level::get(Window& w);
    int window;
public:
    Window(void): window(2) {}
    void show(void);
};

void Window::show(void)
{
    cout << "window" << endl;
}

int Level::get(Window& w)
{
    return w.window + level;
}

int main() …
Run Code Online (Sandbox Code Playgroud)

c++ encapsulation class friend

5
推荐指数
1
解决办法
254
查看次数

标签 统计

c++ ×1

class ×1

encapsulation ×1

friend ×1