C++ Vector of vectors

后端 未结 5 1074
不思量自难忘°
不思量自难忘° 2021-02-06 01:56

I have a class header file called Grid.h that contains the following 2 private data object:

vector column;
vector> row;
         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 02:41

    I think you want something like this... (although I cannot imagine why :-))

    #include 
    #include 
    
    using namespace std;
    
    typedef vector row;
    typedef vector matrix;
    
    matrix mat(2,2);
    
    int getElement (unsigned int ri, unsigned int ci)
    {
        return mat[ri][ci] ;
    }
    
    int main() {
    
        mat[1][0] = 1234;
        cout << getElement(1,0) << endl;
    
        return 0;
    }
    

提交回复
热议问题