I'm attempting to initialize an array of class objects across a .h and .cpp file. I initially declared it(game_map[12]) in the .h file as shown below:
#include <string>
using namespace std;
class Game {
public:
Game();
~Game();
void test();
void InitializeMap(Game &game);
private:
class Room {
public:
Room (string desc);
Room();
~Room();
void PrintDesc(Room ¤t);
void SetDirection(int array_index, Room ¤t);
string description;
static int adjacent[3];rooms.
static string direction[4];
};
static Room game_map[12]; //Here is my array declaration
};
.
.
.
.
However, when I try to initialize game_map in the implementation file...
#include "Game.h"
using namespace std;
/*Public members*/
Game::Game(){}
Game::~Game(){}
/*Private members*/
Room Game::game_map[12] = {Room("scary")}; //trying to initialize here
.
.
.
/*Room*/
int Game::Room::adjacent[] = {-1,-1,-1};
string Game::Room::direction[] = {"-1","-1","-1","-1"};
Game::Room::Room() {}
Game::Room::Room(string descript) {
description = descript;
}
Game::Room::~Room() {}
.
.
.
I get an error saying that Room is undefined, despite that fact that the Room constructor on the right hand side seems to be recognized. I've tried putting the declaration after the Room constructor, but that didn't fix the problem. Can someone tell me what is going on here?
Thanks!
Game::Room, notRoom