语义问题:调用'displayBoard'没有匹配函数
Semantics Issue: No matching function for call to 'displayBoard'
我只是用一个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函数的两个调用中都给出了错误。我不明白我做错了什么。
您之前已经声明了函数定义
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()
playerTurn
中的board
包含char
,但displayBoard
中的参数希望它包含int
。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 内置函数可查看CPP中的成员变量
- 如何获取std::result_of函数的返回类型
- 如何在c++中为模板函数实例创建快捷方式
- 语义问题:调用'displayBoard'没有匹配函数