I want to set the elements of a 2d array equal to zero but I want the array to be defined via variables. Afterwards, I would like to print this matrix. The solutions that I have found, for example here Initialize multidimensional array with zeros, work only when the matrix is defined as myArray[12][8]
, whereas I need them to be defined as
int n = 80;
int m =100;
double myArray[n][m];
I had the same problem when I tried to implement a function that prints the 2d array. For example:
template <typename T, size_t N, size_t M >
void Print2D_dArray(T(&myarray)[N][M]){
for(int i=0; i<N; i++){
for(int j=0; j<M; j++){
std::cout << myarray[i][j] << " ";
}
std::cout << std::endl;
}
}//Print2D_dArray
When I passed a matrix like myArray[10][10]
it would compile and print the array. When I use variables I am getting the error "template argument deduction/substitution failed".