I've started working on a game. I'm pretty new to C++, but not to programming.
Anyway, I have separate classes for characters and maps. I've defined the map class before the character class, so I can have a reference to the map the character is on in the character class (for calculating passability etc).
However, I also want to have an array of references to characters in the map, so I can iterate through each character (for example, to check whether the player is next to another character).
Basically, what I'm after is how would I go about getting two classes to contain references to each other? If I define the map class before the character class, I can refer to a map in the character class, and vice-versa. However, I don't know how I'd do both.
I thought of defining a superclass for characters before the map, so I could refer to the superclass (and hence the actual character class would work), but I'm sure there must be a better way.
Also, related to this, would it then be best to put all my class declarations in a header file? At the moment, I have each class contained in its own CPP file...
Yes, you could do that. Define the class in the header file and implement its functions in a .cpp file. For example, if I have a rectangle class I could put the variable and function declarations of that class in the header file and implement the functions in a .cpp file.