can't pass array to to function

Why don't this match together?
1
2
3
4
5
6
7
8
void fnc( int ** arr) { }

int main()
{
    int arr[2][3];
    
    fnc( arr );
}

Here the compiler error:
1
2
3
4
5
6
7
error: no matching function for call to 'fnc'
    fnc( arr );
    ^~~
arrtest.cpp:1:6: note: candidate function not viable: no known conversion from
      'int [2][3]' to 'int **' for 1st argument
void fnc( int ** arr) { }
     ^
You will need to cast your function call to match your function definition.
But I thought, an array will be passed as pointer. Why doesn't match this pointer to the array signature? And how need I cast the argument at the function call?
Well, the hint is in the compiler's message: the argument you are passing is a two-dimensional array of integers, and the compiler wants int **.

So look here to see if this helps: http://www.cplusplus.com/doc/tutorial/typecasting/
Yes, a cast to 'int**' works. But i thought, int[][] and int** would be the same thing for a function signature, because the int[][] will implicitly convertet to int** inside the function. I wonder why this isn't so.
I think because using the stl containers are better solutions than "C"-style arrays?
That could be. When I compile my example with a C-compiler, I get a warning instead of an error.
Topic archived. No new replies allowed.