【发布时间】:2015-11-10 03:06:24
【问题描述】:
我只是在调用一个以二维数组作为参数的函数。我不明白为什么它告诉我没有要调用的函数,我可以看到该函数。
这是我的代码开头的原型:
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 函数的两个调用中都给了我错误。 我不知道我做错了什么。
【问题讨论】:
-
语义问题:对“displayBoard”的调用没有匹配的函数