I have defined:
const vector<vector<int>> *ElementLines::Quad4 = new vector<vector<int>>
{
{ 0, 1 },
{ 1, 2 },
{ 2, 3 },
{ 3, 0 }
};
Later on, I want to iterate over that collection, to which an object is pointing:
for (int j = 0; j < e->LinesIndices->size(); j++)
{
int n1Index = e->LinesIndices[j][0]; //I expect 0 (for j = 0)
int n2Index = e->LinesIndices[j][1]; //I expect 1 (for j= 0)
}
The code above won't compile:
no suitable conversion function from "const std::vector<int, std::allocator<int>>" to "int" exists
But if I add LinesIndices[j][0][0]
it indeed delivers an int. I don't quite understand what is happening here. To access a vector I just use one pair of square brackets [i]
, is it different for this nested vector of vectors? (I would expect to be able accessing the contents by using two pairs of square brackets).