Base class has incomplete type
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.
Here is my 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__) */
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__) */
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.
An incomplete class declaration is a class declaration that does not define any class members. You cannot declare any objects of the class type or refer to the members of a class until the declaration is complete.
An incomplete type is a type that describes an identifier but lacks information needed to determine the size of the identifier. An incomplete type can be: A structure type whose members you have not yet specified. A union type whose members you have not yet specified.
This error usually means that you are trying to follow a pointer to a class, but the compiler did not find the definition of that class (it found a declaration for the class, so it is not considered an unknown symbol, but it did not find a definition, so it is considered an incomplete class).
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.
In Entity.h
you don't need:
#include "OGRE/Ogre.h"
#include "OgreInit.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"
the only one you actually need is Entity.h
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With