基类有不完整的类型错误(Base class has incomplete type error)

2019-08-01 02:03发布

基类有不完整的类型

这究竟错误意思,我该如何解决? 我曾尝试着通过声明做类class Entity在我EntityPhysics头,但没有奏效。

这里是我的Entity.h

#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__) */

而我EntityPhysics.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在子类中,但如果我这样做,我得到了同样的错误。

Answer 1:

这很可能是由于包括圆形和解决这个问题是去除的方式包括,你不需要他们。

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



Answer 2:

我有我通过移动低#包括向下的标题文件,以便类定义和方法定义,其他的#includes欲望比其它标题提前到来包括解决类似的错误消息。



文章来源: Base class has incomplete type error
标签: c++ oop