【发布时间】:2019-10-17 09:35:33
【问题描述】:
我在 * 中看到了一个关于如何在函数中传递 2d-array 的答案,当我尝试其中一个时,给出了 3 种或更多方法,效果很好。但是当我尝试使用该方法进行回溯时,它给了我一个错误。
我尝试在全局范围内声明它,但我想学习如何以这种方式使用它
#include<bits/stdc++.h>
using namespace std;
int callAgain(int,int);
int call(int,int);
int call(int arr[][5],int n)
{
if(n==1)
return 0;
cout<<"anything";
callAgain(arr,n-1); //getting error here.
return 0;
}
int callAgain(int arr[][5],int n)
{
call(arr,n);
return 0;
}
int main(){
int arr[5][5];
memset(arr,0,sizeof(arr));
call(arr,5);
return 0;
}
错误:从 int(*)[5] 到 int [-fpremissive] 的无效转换
【问题讨论】:
-
您显示的代码存在很多问题(以here 开头)。基本的罪魁祸首是在 c++ 代码中使用 原始 c 样式数组。你应该学习如何正确地促进
std::array和std::vector。
标签: c++ recursion multidimensional-array pass-by-reference call-by-value