C++ 基类有不完整的类型错误

C++ 基类有不完整的类型错误,c++,oop,C++,Oop,基类的类型不完整 这个错误到底意味着什么?我如何修复它?我已经尝试通过在EntityPhysics标头中执行类实体来向前声明该类,但没有成功 这是我的实体 #ifndef __Game__Entity__ #define __Game__Entity__ #include <iostream> #include <string> #include "OGRE/Ogre.h" #include "OgreInit.h" class Entity{ public:

基类的类型不完整

这个错误到底意味着什么?我如何修复它?我已经尝试通过在EntityPhysics标头中执行
类实体
来向前声明该类,但没有成功

这是我的实体

#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__) */
\ifndef\uu游戏\uu实体__
#定义游戏实体__
#包括
#包括
#包括“食人魔/OGRE.h”
#包括“OgreInit.h”
类实体{
公众:
实体(std::string entityId,std::string mesh,Ogre::Vector3 position=Ogre::Vector3::ZERO,Ogre::Vector3 rotation=Ogre::Vector3::ZERO);
虚拟~实体()=0;
无效设置位置(食人魔:矢量3位置);
食人魔::矢量3 getPosition();
void setRotation(食人魔::矢量3旋转增量);
食人魔::矢量3 getRotation();
void setMesh(std::string meshName);
std::string getMesh();
虚空勾号()=0;
无效删除();
Ogre::Entity getEntity();
食人魔::SceneNode getSceneNode();
std::string entityId;
受保护的:
食人魔::实体*ent;
食人魔::场景节点*点头;
};
#endif/*已定义(_游戏__实体__)*/
还有我的整个物理学

#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__) */
\ifndef\uu游戏\uu实体物理__
#定义游戏物理__
#包括
#包括
#包括“食人魔/OGRE.h”
#包括“OgreBulletCollisionsBoxShape.h”
#包括“OgreBulletDynamicsRigidBody.h”
#包括“实体h”
#包括“OgreInit.h”
类EntityPhysics:公共实体//此处出现错误:“基类的类型不完整”
{
公众:
实体物理(std::string pentityId、std::string mesh、Ogre::Vector3位置、Ogre::Vector3旋转、/*特定于物理的“填充”*/std::string shapeForm=“BoxShape”、浮点摩擦力=1.0、浮点恢复=0.0、浮点质量=1.0);
虚拟~EntityPhysics()=0;
虚空勾号()=0;
私人:
浮动摩擦、恢复、质量;
OgreBulletCollisions::CollisionShape*CollisionShape;
OgreAlletDynamics::刚体*刚体;
};
#endif/*已定义(_游戏_实体物理__)*/

我认为这可能与我在子类中包含
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向下移动到头文件的下方来解决该错误,以便另一个#包含的类定义和方法定义早于另一个头文件包含的类定义和方法定义。

您不能向前声明一个类,然后使用它比如说继承的转发声明。使用前向声明的类型所能做的就是声明指向该类型的指针或引用。也不是说这两个类都包含纯虚函数,因此,您不能直接创建这两个类的实例。此外,您不应该在标识符中使用双下划线。以双下划线开头的标识符保留供编译器使用。@EdS.,包含双下划线的标识符保留()。不知什么原因,我花了很多时间仔细阅读,才收到那封信。此外,用下划线启动全局作用域标识符将使其处于同一条船上。Xcode自动生成那些双下划线,因此我认为这将是正常的,因为编译器附带的工具会这样做…@notrodash-该工具是错误的。保留包含两个下划线的名称以及以下划线开头并后跟大写字母的名称。我需要cpp文件中与之配套的一些其他类。看起来,
Entity.h
中仍然需要
OrgeInit.h
,因为那里定义了
Ogre::Vector3::ZERO
。@notrodash cpp文件可以包含其他文件,这很好。OgreInit实际上是我创建的一个自定义头,用于为我加载Ogre。@LuchianGrigore我尝试了编辑,错误仍然存在。我总是被告知我可以转发声明以修复循环包含。。。