语义问题:没有匹配函数来调用 'displayBoard'
Semantics Issue: No matching function for call to 'displayBoard'
我只是调用一个以二维数组作为参数的函数。我不明白为什么它告诉我没有函数可以调用,我可以看到函数。
这是我代码开头的原型:
void displayBoard(int [][COLS], int);
这是调用 displayBoard 的函数和 displayBoard 函数:
void playerTurn()
{
char board[ROWS][COLS] = {{'*', '*', '*'}, {'*', '*', '*'}, {'*', '*', '*'}};
char row, col;
displayBoard(board, ROWS);
cout << "Player X's Turn.\nEnter a row and a column to place an X.\nRow: ";
cin >> row;
cout << "\nColumn: ";
cin >> col;
//clear screen
//edit contents of 2D array
displayBoard(board, ROWS);
cout << "Player O's Turn.\nEnter a row and a column to place an X.\nRow: ";
cin >> row;
cout << "\nColumn: ";
cin >> col;
//Validate each user's move (make sure there isn't an x or o already there
//Ask for a re-input is validation fails
}
void displayBoard(const char board[][COLS], int ROWS)
{
cout << setw(14) << "Columns" << endl;
cout << setw(14) << "1 2 3 " << endl;
cout << "Row 1: " << board[0][0] << " " << board[0][1] << " " << board[0][2] << endl;
cout << "Row 2: " << board[1][0] << " " << board[1][1] << " " << board[1][2] << endl;
cout << "Row 3: " << board[2][0] << " " << board[2][1] << " " << board[2][2] << endl;
cout << endl;
}
它在 playerTurn 函数的两次调用中都给出了错误。
我不知道我做错了什么。
board
in playerTurn
包含 char
,但 displayBoard
中的参数期望它包含 int
.
你在函数定义之前已经声明了
void displayBoard(int [][COLS], int);
然后在playerTurn()
你调用
displayBoard(board, ROWS);
此处 board
是一个 char board[ROWS][COLS]
,因此编译器会查看是否已声明或定义名为 displayBoard
的函数接受这些参数。由于编译器没有看到它,它会发出错误。
要解决此问题,您需要将减速更改为
void displayBoard(const char board[][COLS], int ROWS);
或者您可以只更改函数的顺序并在 displayBoard()
之前定义 playerTurn()
我只是调用一个以二维数组作为参数的函数。我不明白为什么它告诉我没有函数可以调用,我可以看到函数。
这是我代码开头的原型:
void displayBoard(int [][COLS], int);
这是调用 displayBoard 的函数和 displayBoard 函数:
void playerTurn()
{
char board[ROWS][COLS] = {{'*', '*', '*'}, {'*', '*', '*'}, {'*', '*', '*'}};
char row, col;
displayBoard(board, ROWS);
cout << "Player X's Turn.\nEnter a row and a column to place an X.\nRow: ";
cin >> row;
cout << "\nColumn: ";
cin >> col;
//clear screen
//edit contents of 2D array
displayBoard(board, ROWS);
cout << "Player O's Turn.\nEnter a row and a column to place an X.\nRow: ";
cin >> row;
cout << "\nColumn: ";
cin >> col;
//Validate each user's move (make sure there isn't an x or o already there
//Ask for a re-input is validation fails
}
void displayBoard(const char board[][COLS], int ROWS)
{
cout << setw(14) << "Columns" << endl;
cout << setw(14) << "1 2 3 " << endl;
cout << "Row 1: " << board[0][0] << " " << board[0][1] << " " << board[0][2] << endl;
cout << "Row 2: " << board[1][0] << " " << board[1][1] << " " << board[1][2] << endl;
cout << "Row 3: " << board[2][0] << " " << board[2][1] << " " << board[2][2] << endl;
cout << endl;
}
它在 playerTurn 函数的两次调用中都给出了错误。 我不知道我做错了什么。
board
in playerTurn
包含 char
,但 displayBoard
中的参数期望它包含 int
.
你在函数定义之前已经声明了
void displayBoard(int [][COLS], int);
然后在playerTurn()
你调用
displayBoard(board, ROWS);
此处 board
是一个 char board[ROWS][COLS]
,因此编译器会查看是否已声明或定义名为 displayBoard
的函数接受这些参数。由于编译器没有看到它,它会发出错误。
要解决此问题,您需要将减速更改为
void displayBoard(const char board[][COLS], int ROWS);
或者您可以只更改函数的顺序并在 displayBoard()
playerTurn()