Nick Forrington wrote:[color=blue]
> Hi, was wondering if anyone could help me out here, either by someone
> telling me how to do what I'm trying to do or by letting me know it
> can't be done...
>
> I've got a Game class and an Entity class, the Game has a number of
> entities in it, and I want the entity to have a reference to the game
> class.
>
> The compiler obviously doens't like this. I read someone where about a
> solution of just declaring the Game class "class Game;" without
> including the file, or vice versa, but this just makes the compiler
> complain when I try to access a method of the Game class.
>[/color]
Take all the manuals off your desk, pile them on top of your chair so
you can see over the top of your cubicle walls and shout "Does anybody
know how to read a FAQ?"
http://www.parashift.com/c++-faq-lit...html#faq-38.11
You can use the forward decalration to declare the classes, but before
you actually use the members, you have to fully declare the class.
class Game;
class Entity {
public:
Entity(Game* g);
private:
Game* my_game;
};
class Game {
public:
void Member();
};
Entity::Entity(Game* g) : my_game(g) {
my_game->Member();
}