Basically I’m trying to make a chess engine in c++, and to store the board I use 2d string array define as string board[8][8] = startingBoard
(startingBoard
is a macro). The initialisation works well and does not produce any errors or warnings.
But, when I tried to make a void function to reset the board :
inline void resetBoard()
{
board = startingBord;
}
it gives me me two errors at compile time:
- at
board
:Expression must be a modifiable lvalue
- at
startingBoard
:too many initializer values
I’ve also tried to set each values individually :
void resetBoard()
{
string sb[8][8] = startingBord;
int i = 8;
int j = 8;
while (i--) {
while (j--) {
board[i][j] = sb[i][j];
}
}
}
which did not give me errors at compile time but did crash the programm when the function was called.
Astroloico is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.