I am programming a small game in C++ as an exercise, and I've come across a conundrum.
The basic idea is that a Level
has a vector
of Entity
, and each Entity
instance knows which level it belongs to. Pretty straightforward so far.
I was getting some nasty compile errors in my Entity class as it couldn't figure out what Level
was. A simple forward class declaration right before the declaration of Entity
easily fixed that. However, I am already including "Level.h"
in "Entity.h"
. And Level
and Entity
are both declared and defined in the same namespace.
Note: Entity.h
also includes Level.h
.
#include "Level.h"
namespace GameNS {
// Required, otherwise the compiler complains
class Level;
class Entity
{
public:
...
Shouldn't the compiler already know what Level
is, by the time it reaches Entity
?