The problem is you didn’t declare col
nowhere. Because of this the compiler will complain because mat
is a parameter, but col
he doesn’t know what it is.
Also, in C++, if you want to set the size of the matrix in the parameter, you have to do it statically. That is, the exact size has to be known at compile time. The reason is that in order for the compiler to be able to type check, it must have complete knowledge of the type at compile time, and therefore the type cannot depend on something that only exists during execution.
And more importantly: In order for the compiler to calculate how much memory space each element will occupy, he will need to know at compile time what size each position of the array parameter occupies. Since the type of the parameter is an array (array of arrays), then the compiler necessarily needs to know the exact size at compile time of all dimensions except the first.
So this is not valid:
int a, b, c;
// Erro, os valores a, b e c não estão disponíveis em tempo de compilação, só em tempo de execução.
void funcaoQualquer(int mat[a][b][c]) {
}
But this is valid, because the compiler knows exactly what the size of each dimension is:
void funcaoQualquer(int mat[5][5][5]) {
}
That’s valid from here, too. Although the compiler does not know the size of the array as a whole, he knows the size of each element in the first dimension.
void funcaoQualquer(int mat[][5][5]) {
}
Already these here are not valid. The compiler has no way of knowing what is the size of each element in the first dimension:
void funcaoQualquer1(int mat[][][5]) {
}
void funcaoQualquer2(int mat[][][]) {
}
void funcaoQualquer3(int mat[5][][]) {
}
void funcaoQualquer4(int mat[5][5][]) {
}
void funcaoQualquer5(int mat[][5][]) {
}
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero