• 14
• 12
• 9
• 10
• 13

# C++, undefined base class

This topic is 4150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok, this seems like an easy question. I've been looking at this code for 2 days and I just don't see it. Normally I can figure out a simple compiler error, but I can't see what's causing it. It seems like my base class is defined, but it says it isn't. So if you can take the time to help me I would appreciate it. gameobject_vehicle.hpp(14) : error C2504: 'MultiGameObject' : base class undefined okay just look at the code and see if you can find what's causing it. To help understand my object inheritance tree, just think GameObject -> MultiGameObject -> Vehicle GameObject.hpp
#ifndef GAME_OBJECT_HPP
#define GAME_OBJECT_HPP

#include "Vector2f.hpp"
#include "GameObjectBoundaryManager.hpp"

namespace Ancient
{

enum ObjectType;

class GameObject
{
public:
Vector2f pos;
GameObject * ParentObject;

virtual ~GameObject();

virtual ObjectType GetType() = 0;
virtual GameObject * Clone() = 0;

virtual void Initialize();
virtual Vector2f * GetPosition();
virtual void SetBoundary(BoundaryBox * boundaryBox);
virtual int GetRenderLayer();

};

}

#endif /* GAME_OBJECT_HPP */


GameObject.cpp
#include "GameObject.hpp"

namespace Ancient
{

GameObject::~GameObject(){}

void GameObject::Initialize(){}

Vector2f * GameObject::GetPosition(){return &pos;}

void GameObject::SetBoundary(BoundaryBox * boundaryBox){}

int GameObject::GetRenderLayer(){return 0;}

}


GameObject_MultiGameObject.hpp
#ifndef GAME_OBJECT_MULTI_GAME_OBJECT_HPP
#define GAME_OBJECT_MULTI_GAME_OBJECT_HPP

#include <vector>

#include "GameObject.hpp"
#include "ObjectFactory.hpp"

namespace Ancient
{

class GameObject;

class MultiGameObject : public GameObject
{
public:
std::vector<GameObject*> mObjects;

virtual ~MultiGameObject();
virtual ObjectType GetType();
virtual GameObject * Clone();
};

}

#endif /* GAME_OBJECT_MULTI_GAME_OBJECT_HPP */


GameObject_MultiGameObject.cpp
#include "GameObject_MultiGameObject.hpp"

namespace Ancient
{

MultiGameObject::~MultiGameObject(){

}

ObjectType MultiGameObject::GetType(){
return MULTIGAMEOBJECT;
}

GameObject * MultiGameObject::Clone(){
GameObject * pNewObject = NULL;

return pNewObject;
}

}


GameObject_Vehicle.hpp
#ifndef GAME_OBJECT_VEHICLE_HPP
#define GAME_OBJECT_VEHICLE_HPP

//#include "Vector2f.hpp"

#include "GameObject_MultiGameObject.hpp"
//#include "ObjectFactory.hpp"

namespace Ancient
{

class Vehicle : public MultiGameObject
{
public:
//Vector2f velocity;
//Vector2f offsetView;

Vehicle();

ObjectType GetType();
GameObject * Clone();
};

}

#endif /* GAME_OBJECT_VEHICLE_HPP */


GameObject_Vehicle.cpp
#include "GameObject_Vehicle.hpp"

#include "GameObject.hpp"

namespace Ancient
{

Vehicle::Vehicle(){

}

ObjectType Vehicle::GetType(){
return VEHICLE;
}

GameObject * Vehicle::Clone(){
GameObject * pNewObject = NULL;

return pNewObject;
}

}


Those are the three classes. Is there anything else that can cause this kind of error? I am completely stuck. note: I'm fleshing out my classes so they might not make much sense, just trying to get the structure down.

##### Share on other sites
Where is the enum ObjectType defined? I see the declaration, but is that enough to allow the GameObject class to be defined?

Also, you don't need the class GameObject; fwd declaration in GameObject_MultiGameObject.hpp, since you're including GameObject.hpp (which you have to, since you're inheriting from GameObject).

##### Share on other sites
The enum ObjectType is in the ObjectFactory.hpp. But I get what your saying, I'll try to see if that changes it. Thank you very much.

//edit, okay I have been messing with the enum and it's definitely the thing causing the error.

//edit, yah it works!

[Edited by - Sirisian on November 10, 2006 10:26:40 PM]