基类有不完整的类型错误 [英] Base class has incomplete type error

查看:80
本文介绍了基类有不完整的类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基类的类型不完整

Base class has incomplete type

此错误的确切含义是什么,我该如何解决?我已经尝试通过在EntityPhysics标头中执行class Entity来声明该类,但是它不起作用.

What exactly does this error mean and how can I fix it? I have tried forward declaring the class by doing class Entity in my EntityPhysics header but it did not work.

这是我的实体.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

And my 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,但如果这样做,我会遇到相同的错误.

I think it may have to do with me including Entity.h in the child class, but if I do that I get the same error.

推荐答案

这很可能是由于循环包含,而解决此问题的方法是在不需要它们的地方删除包含.

This is most likely due to a circular include, and the way to fix this is to remove includes where you don't need them.

Entity.h中,您不需要:

#include "OGRE/Ogre.h"
#include "OgreInit.h"

您可以而且应该转发声明这些类型.与EntityPhysics.h和:

You can, and should, instead forward-declare the types. Same for EntityPhysics.h and:

#include "OGRE/Ogre.h"
#include "OgreBulletCollisionsBoxShape.h"
#include "OgreBulletDynamicsRigidBody.h"

#include "OgreInit.h"

您真正需要的唯一一个是Entity.h.

the only one you actually need is Entity.h.

这篇关于基类有不完整的类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆