I'm trying to set the size of an array to an input received by the program, currently the size of the array is defined as a const static int
.
Board.h
#include <iostream>
using namespace std;
class Board {
private:
const static int BOARDSIZE = 5;
char board[BOARDSIZE][BOARDSIZE];
const char p1Symbol = 'R';
const char p2Symbol = 'B';
const char trail = 'O';
const char crash = '*';
int p1Row;
int p1Col;
int p2Row;
int p2Col;
public:
void setBoardSize(int size);
bool isValidMove(int row, int col);
bool isValidInput(char input);
bool getNextMove();
void initializeArray();
void drawHorizontalSeparator();
void drawSeparatedValues(int row);
void displayBoard();
};
Main
#include <iostream>
#include "Board.h"
using namespace std;
int main() {
int size;
cout << "Enter and integer between 4 and 20 for the BoardSize: " << endl;
cin >> size;
Board b;
b.setBoardSize(size);
b.initializeArray();
b.displayBoard();
bool done = false;
while (!done) {
done = b.getNextMove();
}
return 0;
}
I'm trying to use this function called setBoardSize
to change the size of the board in the Board.H
file. I've tried removing const static
but then I get all sorts of errors. Apparently it isn't possible to define an array that doesn't have a predefined size?