我需要将2D数组传递给函数,但它不适合我。它说"没有匹配功能来调用display_board"。我需要让用户定义2D数组的大小并将其传递给函数。应该很容易,但我无法让它发挥作用。需要帮忙!!非常感谢!!
void display_board(int r, int c, char b[][c])
{
for (int i=0; i<r; i++) { //print out the board. Need to be deleted at last.
for (int j=0; j<c; j++) {
cout<<b[i][j];
}
cout<<endl;
}
}
int main()
{
int rows,columns,n;
cout<<"Enter rows: ";
cin>>rows;
cout<<"Enter columns: ";
cin>>columns;
cout<<"Enter n-in-a-row: ";
cin>>n;
char board_info[rows][columns]; //initialze the board
for (int i=0; i<rows; i++) {
for (int j=0; j<columns; j++) {
board_info[i][j]='.';
}
cout<<endl;
}
display_board(rows, columns, board_info);//Says "no matching function for call to display_board"
for (int i=0; i<rows; i++) { //print out the board. Need to be deleted at last.
for (int j=0; j<columns; j++) {
cout<<board_info[i][j];
}
cout<<endl;
}
}