I want to make class library, a function which its parameter is a matrix of unknown size, and the user will create his own matrix with his own size and pass it to this function to do some operations on his matrix like this, will be the function
calculateDeterminantOfTheMatrix( int matrix[][])
{
some Operations to do on matrix
}
Multi-dimensional arrays are not very well supported by the built-in components of C and C++. You can pass an
N-dimension array only when you knowN-1dimensions at compile time:However, the standard library supplies
std::vectorcontainer, that works very well for multi-dimension arrays: in your case, passingvector<vector<int> > &matrixwould be the proper way of dealing with the task in C++.As an added bonus, you wouldn’t need to pass dimensions of the matrix to the function:
matrix.size()represents the first dimension, andmatrix[0].size()represents the second dimension.