multidemensional argument

1
2
3
4
5
6
7
8
9
void printMatrix(int x[][]){
    cout << "Matrix " << x << ":" << endl;
    for(int r=0;r<rows;r++){
        for(int c=0;c<colums;c++){
                cout << x[r][c] << "\t";
        }
        cout << endl;
    }
}


Error: declaration of 'x' as multidimensional array must have bounds for all dimensions except the first

How can i use multidimensional array with unknown bounds?
Last edited on
You may not declare a multidimensional array as a function parameter without specifying its bounds except the first as the error message says..
Use std::vector instead.

For example

1
2
3
4
5
6
7
8
9
void printMatrix( const std::vector<std::vector<int>> &m ){
    cout << "Matrix :" << endl;
    for ( size_t r=0; r < m.size(); r++){
        for( size_t c = 0; c < m[r].size(); c++ ){
                cout << m[r][c] << "\t";
        }
        cout << endl;
    }
}
Last edited on
Topic archived. No new replies allowed.