【发布时间】:2021-01-05 07:54:26
【问题描述】:
这是我的代码:
void printArray(int **A, int m, int n)
{
int row = m;
int col = n;
int **array;
array = new int *[row];
for (int i = 0; i < row; ++i)
{
array[i] = new int[col];
}
for (int p = 0; p < row; p++)
{
for (int l = 0; l < col; l++)
{
cout << array[row][col] << " ";
}
}
}
int main()
{
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
cout << printArray(arr, 3, 3); // error:
// invalid conversion from 'int' to 'int**' [-fpermissive]|
}
谁能告诉我我在函数调用中做错了什么?
【问题讨论】:
-
我没有看到指针A在函数中的使用位置。
-
请在问题中包含完整的错误消息。它应该包含更多信息,也许您无法破译它,但存在错误消息以帮助您找到代码中的错误
-
我不确定如何将
**A链接到**array,然后在main 中正确调用该函数。 - 谢谢弗拉德 -
错误:||=== 构建文件:“无项目”中的“无目标”(编译器:未知)===| C:\Users\tf\Documents\Data Structures and Algorithms in c++\C++ Book\R-1.9.cpp||在函数'int main()'中:| C:\Users\tf\Documents\Data Structures and Algorithms in c++\C++ Book\R-1.9.cpp|42|error: cannot convert 'int ()[3]' to 'int* '| C:\Users\tf\Documents\Data Structures and Algorithms in c++\C++ Book\R-1.9.cpp|4|注意:初始化'void printArray(int**, int, int)'的参数1| ||=== 构建失败:1 个错误,0 个警告(0 分钟,1 秒)===|
标签: c++ multidimensional-array output function-definition