【发布时间】:2015-09-21 15:04:39
【问题描述】:
我正在尝试将多维数组传递给函数。当我尝试编译时出现错误提示
[Error] cannot convert 'int (*)[3]' to 'int (*)[2]' for argument '1' to 'void reve(int (*)[2], int)'
有什么问题?我究竟做错了什么?以下是我写的代码。
#include <iostream>
using namespace std;
const int rows=2;
const int cols=2;
const int n = 3;
void reve(int arr[rows][cols],int n){
int br[3][3],i,j,k,l;
for(i=n-1,k=0;i>=0,k<n;i--,k++){
cout<<endl;
for(j=n-1,l=0;j>=0,l<n;j--,l++)
br[k][l]=arr[i][j];
}
for(i=0;i<n;i++){
for(j=0;j<n;j++)
arr[i][j]=br[i][j];
}
}
int main() {
int i,j,k,l,ar[3][3],br[3][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>ar[i][j];
int n=3;
reve(ar,n);
for(i=0;i<3;i++){
cout<<endl;
for(j=0;j<3;j++)
cout<<ar[i][j];
}
return 0;
}
【问题讨论】:
-
请显示编译器给出的完整错误。
-
i>=0,k<n等于k<n。你的意思是i>=0 && k<n? -
这就是你的错误:无法将参数 '1' 的 'int ()[3]' 转换为 'int ()[2]' to 'void reve (int (*)[2], int)'