在两个不同的类中包含相同的头文件

Including the same header file in two different classes

本文关键字:包含相 文件 两个      更新时间:2023-10-16

所以我有类A、B和C。类A是父类或基类,B和C从中继承。我收到错误,说"基类未定义"。我相信这是因为类A包含在B和C的头文件中?这在我的主代码中。

#include "BoundingSphere.h"
#include "OrientedBoundingBox.h"

这是BoundingSphere.h 的缩短版本

#include "Model.h"
#include "Commonxnacollision.h"
class BSModel : public Model
{
};

OrientedBoundingBox.h与类OBBModel是一样的。为什么我会出错Error 2 error C2504: 'Model' : base class undefined c:usersXdesktopprojectboundingsphere.h 9 1 PhysicsDemo

我还得到了"模型"重新定义错误。

尝试将#pragma once放在项目中所有头文件的顶部,以防止在已经包含它们后重新包含它们。

所有现代编译器都支持#pragma once,但不是标准的。您也可以使用标准的防护罩。