Why do I get "error C2504: 'CEntity' : base class undefined" errors, when all the relevant headers are included?
I have a CMap which does most of the heavy lifting:
// CMap.h
#ifndef _CMAP_H_
#define _CMAP_H_
#include "CEntity.h"
class CMap {
public:
CMap(void);
void OnLoad();
void OnRender();
std::vector<CTile*> TileList;
};
#endif
One of the things in the CMap is a list of Tiles:
// CTile.h
#ifndef _CTILE_H_
#define _CTILE_H_
class CEntity; // forward declaration
class CTile {
public:
CTile(void);
std::vector<CEntity*> EntityList;
char Label[0];
};
#endif
Each Tile contains a list of Entities:
// CEntity.h
#ifndef _CENTITY_H_
#define _CENTITY_H_
class CEntity {
public:
CEntity(void);
char Label[0];
};
#endif
There are also various children of CEntity:
// CEntity_Buggy.h
#ifndef _CENTITY_BUGGY_H_
#define _CENTITY_BUGGY_H_
#include "CEntity.h"
class CEntity_Buggy : public CEntity {
public:
CEntity_Buggy(void);
};
#endif
Now, my main map loading routine works fine, as does the rendering routing, which happens to need to peek into the Tiles for some info:
// CMap.cpp
#include "CMap.h"
void CMap::OnLoad() {
...
}
void CMap::OnRender() {
/* here would be some rendering code ... */
std::vector<CTile*>::iterator i;
for (i=this->TileList.begin(); i!=this->TileList.end(); ++i) {
CTile* tile = *i;
for(unsigned int i = 0; i < tile->EntityList.size(); i++) {
label[0] = tile->EntityList[i]->Label[0];
}
}
}
That works fine, and in the full app so far, it draws the cells, and adds the labels from the 'resident' entities. The problem comes when I want to put some specific entity subclasses into the system:
// CMap.h
#include "CEntity_Buggy.h" // add this to the header
// CMap.cpp
#include "CMap.h"
void CMap::OnLoad() {
CEntity_Buggy buggy;
buggy.OnLoad();
}
And now I get lots of \centity_buggy.h(18): error C2504: 'CEntity' : base class undefined
errors, but I'm not sure why. My CEntity_Buggy.h includes CEntity.h.
The full current (and this is a first-C++ project, so it's quite flawed) is available on GitHub, if that helps.