语义问题:调用'displayBoard'没有匹配函数

时间:2015-11-10 03:06:24

标签: c++ call

我只是调用一个以2D数组作为参数的函数。我不明白为什么它告诉我没有调用的功能,我可以看到这个功能。 这是我的代码开头的原型:     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函数的两个调用中都给出了错误。 我无法弄清楚我做错了什么。

2 个答案:

答案 0 :(得分:1)

response.setHeader("Content-Type", "image/jpeg"); response.write(binary) response.end() 中的

board包含playerTurn,但char中的参数需要包含displayBoard

答案 1 :(得分:0)

您已在功能定义之前声明

void displayBoard(int [][COLS], int);

然后在playerTurn()中致电

displayBoard(board, ROWS);

此处boardchar board[ROWS][COLS],因此编译器会查看是否已经看到声明或定义的名为displayBoard的函数,它接受这些参数。由于编译器没有看到它会发出错误。

要解决此问题,您需要将删除更改为

void displayBoard(const char board[][COLS], int ROWS);

或者您只需更改功能的顺序,并在playerTurn()之前定义displayBoard()