c++ class 可以包含一个 class 成员吗?

c++ Can a class contain a class member that is friends with it?

我有一个名为 Restaurant 的 class,其中包含一个 Employee 成员。现在 Employee 是 Restaurant 的朋友 class。当我尝试编译它时,我在 Employee mCurrentEmployee 上收到错误消息,说它缺少类型说明符 - 假定为 int。为什么编译器会为此生我的气?关于如何解决它的任何想法?谢谢。

#pragma once
#include "employee.h"
class Restaurant{
    friend class Employee;

private:
    Employee mCurrentEmployee;

};

-

#pragma once
#include "restaurant.h"
class Employee {

}

如果您从应该解决朋友问题的员工那里删除 "restaurant.h"include(您可能需要使用前向声明来编译代码,但对于某些给定的情况不可能说您向我们展示的最少代码)。

也就是说你应该问问自己,为什么员工首先需要成为餐厅的朋友。