class Board {
public:
friend class Game;
Board() = default;
Board(int n) : N(n) { }
Board& SetType(int, int, char);
void GetType(int, int);
Board& CreateEmptyBoard();
void BoardDisplay();
private:
int N = 0;// dimension
char Maze[15][15];
const static int MaxSize = 15;
};
class Game {
public:
Game() = default;
Game(int x, int y) : PosX(x), PosY(y) { }
void BuildGame();
void GameDisplay();
void MoveUp();
void MoveDown();
void MoveLeft();
void MoveRight();
private:
int PosX = 0;
int PosY = 0;
};
void Game::BuildGame() {
srand(time(NULL));
for (int i = 0; i < Board::N; i++) {
for (int j = 0; j < Board::N; j++) {
if (i == rand() % (Board::N) && j == rand() % (Board::N))
Board::Board& SetType(i, j, 'W');
}
}
}
在遊戲類的成員函數void BuildGame
,我想打電話給成員函數Board& SetType(int,int,char)
類Board.I定義此函數在頭文件中,而不是在這裏顯示。然後我建立這個項目,我得到了invalid use of non-static data member 'Board::N'
和'SetType' was not declared in this scope
。 Like this
我哪裏錯了?我找不到它。
@ildjarn我嚴重懷疑這會解決問題。 –