lundi 21 janvier 2019

How to pass an array containing a game board to a class function defined in a separate .cpp file?

I am working on a project where I am using two Classes, Player and Board, that have prototype methods in header files, definitions in separate .cpp files, and they are both being used in a main.cpp file. When trying to pass an array of gameboard spaces, gameBoard[], into a Method, board.taketurn(gameboard[]), and I receive an error, "identifier "gameBoard" is undefined".

I am new to c++ I learned a lot in C but have some issues with classes.

class Board // Board Class in board.h
{
    public:
    void board();
    int gameBoard[]; //declaration of gameboard[]
    int takeTurn(int, int, string, int gameBoard[]); //method 
prototype
    static const int WIN_SPACE = 100;

    private:
    int spin(int, int, string);
    static const int SPIN_MAX = 6;
    static const int SPIN_MIN = 1;
};



//Method definition in board.cpp
int Board::takeTurn(int position, int prevPos, string playerName, 
int gameBoard[WIN_SPACE])
{
cout<< "it is "<<playerName<<"'s turn. They are currently on space " 
<<gameBoard[position]<<"."<<endl;
    spin(position, prevPos, playerName);
    return position, prevPos;
}


//code block containing call takeTurn, passing gameBoard[] as an arg
 while(player[i].getCurPosition() != board.WIN_SPACE)
        {
            int posititon;
            int prevPos;
            cout << "Press Enter to Continue";
            getchar(); 
            board.takeTurn(player[i].getCurPosition(), 
player[i].getPrevPosition(), player[i].getName(), board 
*gameBoard[board.WIN_SPACE]); //function Call
            //player[i].setCurPosition(position);

        }

I want the function takeTurn to be able to take gameBoard as an argument so I can set player[i]'s position to a location in the array gameBoard[].

Aucun commentaire:

Enregistrer un commentaire