-1

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. 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]

era s'q
  • 537
  • 1
  • 7
  • 27
  • There are a lot of issues with the code you're showing (starts [here](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h)). The basic culprit is to use _raw c-style arrays_ with c++ code. You should rather learn how to facilitate `std::array` and `std::vector` correctly. – πάντα ῥεῖ May 31 '19 at 18:55

1 Answers1

1

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.

Compilers don't appreciate being lied to...

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • Not necessary a lie, might be implemented in another TU :) – Jarod42 May 31 '19 at 18:38
  • @Jarod42: There is exactly *one blank line* between the forward declaration of `call` & its implementation. (And what is a TU?) – Scott Hunter May 31 '19 at 19:00
  • Well, [Translation Unit](https://stackoverflow.com/questions/1106149/what-is-a-translation-unit-in-c), I guess. – Bob__ May 31 '19 at 19:02
  • When I'm calling the call function in my main function and passing an array then also it should have given me an error because like you said the call is also declared with int. – era s'q Jun 02 '19 at 09:36
  • How many times/ways do you want it to tell you this is wrong? – Scott Hunter Jun 02 '19 at 11:05