简体   繁体   English

在C ++中使用递归时无法传递二维数组

[英]Unable to pass 2-Dimensional array while using recursion in c++

I saw an answer in stackoverflow regarding how to pass a 2d-array in a function there are 3 or more methods given when I tried one of them it worked just fine. 我在stackoverflow中看到了一个有关如何在函数中传递2d-array的答案,当我尝试其中的一种时,给出了3种或更多种方法,效果很好。 But when I'm trying to use that method in backtracking it is giving me an error. 但是,当我尝试在回溯中使用该方法时,这给了我一个错误。

I tried declaring it globally but I want to learn how to use it this way 我尝试过在全球范围内进行声明,但是我想学习如何以这种方式使用它

#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;
}

error: invalid conversion from int(*)[5] to int [-fpremissive] 错误:从int(*)[5]到int [-fpremissive]的无效转换

Your forward declarations for call and callAgain promise that the first argument will be an int , but then when you implement them you say the first argument is a 2D array. 您对callcallAgain前向声明保证第一个参数将为int ,但是在实现它们时,您将说第一个参数为2D数组。

Compilers don't appreciate being lied to... 编译器不喜欢被骗...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM