I am writing a tic-tac-toe project in C++. I wrote the game_rule
function to control the game flow and I called it in the game over function I got an error message "no matching function for call to 'game_rule'". I tried every possible way to figure out why but was unsuccessful. I passed the custom 2d array but it doesn't have any effect.
Full code can be seen on:
bool game_rule()
{
if ((board_ele[0][0] == 'X' && board_ele[1][1] == 'X' && board_ele[2][2] == 'X') || (board_ele[0][0] == 'X' && board_ele[0][1] == 'X' && board_ele[0][2] == 'X') || (board_ele[1][0] == 'X' && board_ele[1][1] == 'X' && board_ele[1][2] == 'X') || (board_ele[2][0] == 'X' && board_ele[2][1] == 'X' && board_ele[2][2] == 'X') || (board_ele[0][0] == 'X' && board_ele[1][0] == 'X' && board_ele[2][0] == 'X') || (board_ele[0][1] == 'X' && board_ele[1][1] == 'X' && board_ele[2][1] == 'X') || (board_ele[0][2] == 'X' && board_ele[1][2] == 'X' && board_ele[2][2] == 'X'))
{
return true;
}
else
{
return false;
}
}
void game_over()
{
if (game_rule(board_ele) == true)
{
std::cout << "player 1 is won";
}
if (game_rule(board_ele) == true)
{
std::cout << "player 1 is won";
}
}
You are declaring bool game_rule()
with no inputs however when you do call it here if (game_rule(board_ele)==true)
you pass it inputs.
If you want to pass parameters to game_rule define it so it can receive an input from the same type as board_ele.