0

I'm getting this error message : declaration of 'arr' as multidimensional array must have bounds for all dimensions except the f

#include<bits/stdc++.h> using namespace std; #define ll int #define maxn 131070 #define for1() for(ll i=0;i<n;i++) #define for2() for(ll i=0;i<m;i++) #define for3() for(ll i=0;i<m;i++){ for(ll j=0;j<n;j++) #define pb push_back #define E cout<<endl; int isValid(int nextx,int nexty, int m, int n) { if(nextx>=0 && nextx<m && nexty>=0 && nexty<n) return 1; return 0; } class point { public: int row,col; void mpoint(int x,int y) { row=x; col=y; } }; class node { public: point p; int d; void mnode(point q, int dis) { p.row=q.row; p.col=q.col; d=dis; } }; int shortest(int arr[][], int m, int n, int x, int y) { if(arr[0][0]==0) return -1; bool vis[m][n]; memset(vis,false,sizeof(vis)); queue<node> q; point curr; curr.mpoint(0,0); node t; t.mnode(curr,0); q.push(t); int arrx[]={-1,0,1,0}; int arry[]={0,1,0,-1}; point c; node v; while(!q.empty()) { v=q.front(); c=v.p; if(x==c.row && y==c.col) return v.d; q.pop(); for(int i=0;i<4;i++) { int nextx=c.row+arrx[i]; int nexty=c.col+arry[i]; if(isValid(nextx,nexty,m,n)&& arr[nextx][nexty] && !vis[nextx][nexty]) { curr.mpoint(nextx,nexty); t.mnode(curr,(v.d)+1); q.push(t); vis[nextx][nexty]=true; } } } return -1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); /////////////////////////// start /////////////////////////// int m,n,x,y; cin>>m>>n; int arr[m][n]; for(ll i=0;i<m;i++) { for(ll j=0;j<n;j++) cin>>arr[i][j]; } cin>>x>>y; if(shortest(arr,m,n,x,y)!=-1) cout<<shortest(arr,m,n,x,y); else cout<<"not found:/"; /////////////////////end//////////////////////////////////// return 0; }

15th Jan 2021, 7:31 AM
Morningstar
Morningstar - avatar
1 Answer
+ 4
Firstly, the error message is not fully visible. Secondly, the code is very confusing as we can't see line numbers and because it not linted The solution to both these problems is, save the code in SoloLearn, and share the saved code link in the description. Follow the below guide in case you didn't know how to share links https://www.sololearn.com/post/75089/?ref=app As for the error, the error message says it all. You can't have int arr[][] as a function parameter. You *need* to specify the bounds (length) of all dimensions except the first. Example void func(int arr[][3]); is valid but void func(int arr[][]); is invalid as you saw in your code too. Similarly void func(int arr[][3][3]); is valid, but void func(int arr[][][]); is invalid.
15th Jan 2021, 7:50 AM
XXX
XXX - avatar