mercredi 20 juillet 2016

invalid use of non-static data member 'Board::N'

This is the header.

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');
 }
 }
 }

In class Game's member function void BuildGame,I want to call member functionBoard& SetType(int,int,char) in class Board.I define this function in a header file and not show here. Then I build the project, I gotinvalid use of non-static data member 'Board::N' and 'SetType' was not declared in this scope. Like this: enter image description here Where I wrong? I can't find it.

I am new in c++. Please help me to solve this.

THANKS!

Aucun commentaire:

Enregistrer un commentaire