基类具有不完整的类型错误
Base class has incomplete type error
基类具有不完整的类型
此错误到底是什么意思,我该如何解决?我尝试通过在 EntityPhysics 标头中执行class Entity
来向前声明类,但它不起作用。
这是我的实体。
#ifndef __Game__Entity__
#define __Game__Entity__
#include <iostream>
#include <string>
#include "OGRE/Ogre.h"
#include "OgreInit.h"
class Entity{
public:
Entity(std::string entityId, std::string mesh, Ogre::Vector3 position = Ogre::Vector3::ZERO, Ogre::Vector3 rotation = Ogre::Vector3::ZERO);
virtual ~Entity() = 0;
void setPosition(Ogre::Vector3 position);
Ogre::Vector3 getPosition();
void setRotation(Ogre::Vector3 rotationIncrease);
Ogre::Vector3 getRotation();
void setMesh(std::string meshName);
std::string getMesh();
virtual void tick() = 0;
void removeEntity();
Ogre::Entity getEntity();
Ogre::SceneNode getSceneNode();
std::string entityId;
protected:
Ogre::Entity *ent;
Ogre::SceneNode *nod;
};
#endif /* defined(__Game__Entity__) */
和我的实体物理.h
#ifndef __Game__EntityPhysics__
#define __Game__EntityPhysics__
#include <iostream>
#include <string>
#include "OGRE/Ogre.h"
#include "OgreBulletCollisionsBoxShape.h"
#include "OgreBulletDynamicsRigidBody.h"
#include "Entity.h"
#include "OgreInit.h"
class EntityPhysics: public Entity //error occurs here: "Base class has incomplete type"
{
public:
EntityPhysics(std::string pentityId, std::string mesh, Ogre::Vector3 position, Ogre::Vector3 rotation, /*Physics Specific "stuff"*/std::string shapeForm = "BoxShape", float friction = 1.0, float restitution = 0.0, float mass = 1.0);
virtual ~EntityPhysics() = 0;
virtual void tick() = 0;
private:
float friction, restitution, mass;
OgreBulletCollisions::CollisionShape *collisionShape;
OgreBulletDynamics::RigidBody *rigidBody;
};
#endif /* defined(__Game__EntityPhysics__) */
我认为这可能与我在儿童班中包括Entity.h
有关,但如果我这样做,我会得到同样的错误。
这很可能是由于循环包含,解决此问题的方法是删除不需要它们的包含。
在Entity.h
中,您不需要:
#include "OGRE/Ogre.h"
#include "OgreInit.h"
您可以并且应该改为前向声明类型。EntityPhysics.h
相同,并且:
#include "OGRE/Ogre.h"
#include "OgreBulletCollisionsBoxShape.h"
#include "OgreBulletDynamicsRigidBody.h"
#include "OgreInit.h"
您真正需要的唯一是 Entity.h
.
我有一个类似的错误消息,我通过将 #includes 向下移动到头文件来解决,以便其他 #includes 想要的类定义和方法定义早于另一个标头包含。
当我们想用作基于类但尚未完成(基于类中存在一些错误)时,就会发生这种情况。 只需检查基于类是否一切正常
相关文章:
- 类没有命名C++代码中的类型错误
- 不完整类型错误(E0409、E0070、E0515)
- 使用具有结构不完整类型错误的模板
- 不命名构造函数和析构函数上的类型错误
- 返回派生类型时出现协变类型错误
- 为什么此构造函数没有给出不完整的类型错误?
- 定义模板化结构的特征时出现不完整的类型错误
- 使用重载构造函数时出现不完整的类型错误
- 为什么我得到表达式必须有类类型错误?
- 输出 [left]=input[i] 行中的 c++ 代码中存在无效的类型错误
- 枚举成员不是类型错误
- 如何修复"ctypes"。参数错误:参数 2:<键入"异常.类型错误">:RaspberryPi 中的错误类型"错误
- 外部 "C" Visual Studio 2015 中的显式类型错误,DLL 测试代码
- 非默认析构函数会导致不完整的类型错误
- 为什么按引用传入会导致绑定引用类型错误
- Objective-C C++ 包装器 类型错误的不完整定义
- 输入类型错误
- 当构造函数的参数类型错误时引发异常
- 命名空间中的'bad_cast' 'std' 未命名类型错误
- C UNWORKOWN类型错误