在两个不同的类中包含相同的头文件
Including the same header file in two different classes
所以我有类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
,但不是标准的。您也可以使用标准的防护罩。
相关文章:
- 使用mongocxx驱动程序时包含头文件问题
- 如何在h文件中包含.o对象文件
- 包含模板文件的递归会导致编译失败
- 在C++中包含原型文件的正确方法是什么?
- 包含在.cpp文件中包含在 .h 文件时包含
- 如何为包含头文件的目标编写生成文件?
- 使用提升元解析字符串解析包含的文件
- 在头文件上包含 cpp 文件是否有缺点?
- 如何在 CMakeLists.txt Qt Creator 中包含头文件?
- VS:在构建/exe中包含资源文件
- 无法使包含.hpp文件与其中的2个文件一起使用
- 当包含头文件的文件不在根项目文件夹中时,如何包含它
- 在生成文件先决条件中包含头文件的原因
- 在工厂或C++类中包含数据库 .h 文件
- My Project的属性配置正确,但Visual Studio仍然无法打开包含头文件
- 在 PostgreSQL C 扩展中包含头文件
- 是否可以在C++中以间接方式包含头文件
- 是否需要包含头文件?
- 在Visual Studio C++2017中链接libjpeg-turbo要包含哪些文件
- 我收到未声明的标识符错误,但我已包含头文件?