Hey, so since I am a noob I found myself stuck on a small problem. And the problem is that I have a Entity class that contains a Healthbar instance and I need the healthbar to contain a pointer to its owner (the entity). And this is where I got stuck.
CEntity class:
#ifndef _CENTITY_H_
#define _CENTITY_H_
#include "SDL.h"
class CEntity
{
public:
CEntity();
~CEntity();
public:
bool OnInit();
void OnRender(SDL_Surface* destination);
void OnLoop();
int GetX();
int GetY();
int GetW();
int GetH();
int GetMaxHealth();
int GetCurrentHealth();
private:
SDL_Rect Image;
CHealthBar HealthBar;
int MaxHealth;
int CurrentHealth;
int LastHurtTime;
};
#endif
CHealthBar class:
#ifndef _CHEALTHBAR_H_
#define _CHEALTHBAR_H_
#include "SDL.h"
class CHealthBar
{
public:
CHealthBar();
~CHealthBar();
public:
bool OnInit();
void OnRender(SDL_Surface* _destination);
void OnLoop();
void SetOwner(CEntity* _owner);
private:
CEntity* Owner;
SDL_Rect BarBackground;
SDL_Rect Bar;
int MaxBarLenght;
SDL_Color HighHealth;
SDL_Color AverageHealth;
SDL_Color LowHealth;
};
#endif
The compiler complains about this to no end, what should I do about this? Is this not a good way to handle the way a healthbar is connected to an entity? I've tried to include them here and there to no success, even tried to forward declare and still not getting it to work.
Thanks