The reason why this is not allowed is because f(int P[2][4]) becomes f(int (*P)[4]) , so you can go through int B[3][4] , which can split into int (*B)[4] , but int A[2][3] cannot decay into int (*A)[4] , so f(int (*P)[4]) will not be accepted.
The type int (*)[3] incompatible with int (*)[4] . You can not convert to another!
However, there is a solution. You can do it:
template<size_t M, size_t N> int f(int (&P)[M][N]) { //Use M and N as dimensions of the 2D array! } //Usage int A[2][3]; f(A); //M becomes 2, N becomes 3 int B[3][4]; f(B); //M becomes 3, N becomes 4
It will accept all two-dimensional arrays!
Nawaz source share