I'm working on my own little platformer type game (using c++ and sdl).
Currently, the engine i'v made can load a level from a file, and you can go around the level , there is collision detection, and a simple camera system, so all i need to add now are mobs, items, and a score system.
I'v started working on adding mobs to the game, and ran into a problem:
I have a 'level' class which loads the level data from a file. until now it only loaded the tiles and the 'borders' for the camera, Now i wanted it to load mobs aswell.
I've made a 'mob' class, which inherits a class called 'character' (which the 'player' class also inherits). The mobs work if you make them manually, so all i need to do is make a 'mobs' container in the 'level' class, so i can load into it mobs from the data file.
The problem is:
The 'character' class uses some functions in the 'level' class, so it includes "level.h"
Now the files look like this:
level.h:
Code: Select all
#ifndef LEVEL_H
#define LEVEL_H
#include "mob.h"
class Level
{
...
}
#endif
Code: Select all
#ifndef MOB_H
#define MOB_H
#include "character.h"
class mob : public character
{
...
}
#endif
Code: Select all
#ifndef CHARACTER_H
#define CHARACTER_H
#include "level.h"
class character
{
...
}
#endif
character.h:
Code: Select all
#ifndef CHARACTER_H
#define CHARACTER_H
#include "level.h" // Skipped because LEVEL_H is already defined!
class character
{
...
void someFunction (level *lvl); // Error! 'level' : undeclared identifier
..
}
#endif
level.h:
Code: Select all
#ifndef LEVEL_H
#define LEVEL_H
class level; //declare level class
#include "mob.h"
class level
{
...
}
#endif
But now it gives me a new error:
"error C2504: 'Character' : base class undefined"
mob.h:
Code: Select all
#ifndef MOB_H
#define MOB_H
#include "character.h"
class mob : public character // Error! 'Character' : base class undefined!
{
...
}
#endif
It only does this when i include "mob.h" in "level.h"
Why is this happening??
Can someone please help? Thnx!