Example of the codeFairly new to object oriented programming. I am trying to make a connect 4 game with a class for the overall game, which contains a board object which then contains two player objects. I've realized that I need my players to be able to access some information from the board, specifically row and column lengths (also using pointers so the user can edit the board size), so I was trying to pass a board object to those specific functions as a parameter. I'm getting the undeclared error stated above but I'm just confused on why I would need to declare it in player class when I'm only using it as a parameter.
For example I get this error: error: 'board' has not been declared 25 | int takeTurn(board& myBoard); | ^~~~~
Here's some of the code from my player.h file:
#ifndef PA02_TEMPLATE_PLAYER_H
#define PA02_TEMPLATE_PLAYER_H
#include "board.h"
class player{
private:
protected:
char piece;
int playerMove[2];
int playerNum;
public:
player()= default;
player(char p, int num){
piece = p;
playerNum = num;
}
int takeTurn(board& myBoard);
void colChoice(int i);
void findRow(board& myBoard, int rows);
void setPlayerNum(int i){
playerNum = i;
}
void setPiece(char p){
piece = p;
}
char getPiece(){
return piece;
}
int getPlayerNum(){
return playerNum;
}
};
class aiPlayer : player{
private:
int aiDifficulty = 2;
public:
void setDifficulty(int i){
aiDifficulty = i;
}
int getDifficulty(){
return aiDifficulty;
}
void takeTurn(int rows, int COLS, board& myBoard);
vector<int> minimax(board& miniBoard, int depth, int alpha, int beta, bool maximizingPlayer);
int scorePosition(char piece, char opponents_piece, board& scoringBoard);
};
#endif //PA02_TEMPLATE_PLAYER_H