How to create vector of vectors?

hello.
I try to create vector matrix of ofPoint.
Where is my mistake?

   vector<ofPoint> coords;
   vector <vector <ofPoint>> matrixCoords;
    
   coords.resize(10);    
 
   for (int i = 0; i < 10; i ++) {
      coords[i].x = i * 10;
      coords[i].y = i * 20;
    }
    
    for (int i = 0; i < 5, i ++) {
     matrixCoords.push_back(coords);
    }
    
    ofLog() << matrixCoords[1][1].x;  // NotWork 

why is not work?

ā€œ>>ā€ symbol is special for C++, so insert space between them:

 vector<vector <ofPoint> > matrixCoords;

Thank you. But in original Iā€™m accidentally put space in this place.
I mean is matrixCoords[1][1].x; a correct request or not?

should be

for (int i = 0; i < 5; i ++) {
     matrixCoords.push_back(coords);
}

Full working code with two typos fixed should work fine:

    vector<ofPoint> coords;
    vector <vector <ofPoint> > matrixCoords;

    coords.resize(10);

    for (int i = 0; i < 10; i ++) {
        coords[i].x = i * 10;
        coords[i].y = i * 20;
    }

    for (int i = 0; i < 5; i++) {
        matrixCoords.push_back(coords);
    }

    ofLog() << matrixCoords[1][1].x;  // Should work now and give you "10"
1 Like

Thanks.

With C++11, vector<vector<ofPoint>> matrixCoords is a legal code. I think openFrameworks 0.9.0 will start to suport it. :wink: