Why does at() not return a reference to the element at position n in a vector<vector<pair<int,int> > >?

I have a vector<vector<pair<int,int> > > v1 with 9 vector<pair<int,int> > elements. When I use v1.at(7) I get not just one vector<pair<int,int> > element but 2. I was expecting only one element, the second to last element. How come? Is there a way around?

if(problemsStartAt!=0&&problemsEndAt!=0)
{
v_problem_temp=allPathCoordinates.at(0);
for (const auto& p : v_problem_temp)
{
point[p.first][p.second]=Yellow;
}
cout<<"v_problem_temp.size"<<v_problem_temp.size()<<endl;


v_problem_temp=allPathCoordinates.at(1);
for (const auto& p : v_problem_temp)
{
point[p.first][p.second]=Yellow;
}
cout<<"v_problem_temp.size"<<v_problem_temp.size()<<endl;


v_problem_temp=allPathCoordinates.at(7);
for (const auto& p : v_problem_temp)
{
point[p.first][p.second]=Yellow;
}
cout<<"v_problem_temp.size"<<v_problem_temp.size()<<endl;


v_problem_temp=allPathCoordinates.at(8);
for (const auto& p : v_problem_temp)
{
point[p.first][p.second]=Yellow;
}
cout<<"v_problem_temp.size"<<v_problem_temp.size()<<endl;
}
Output:
v_problem_temp.size20
v_problem_temp.size58
v_problem_temp.size1417
v_problem_temp.size1565
time:36 seconds
You can see in the output see that the elements add up . I know that the v_problem_temp first element is 20, the second is 38, the second to last is 266 and the last is 148. That matches the difference between the two last elements:148, 266 respectively.
Bo
> You can see in the output see that the elements add up
No, we can see that sizes are in increasing order.

> I know that the v_problem_temp first element is 20, the second is 38, the
> second to last is 266 and the last is 148
perhaps you are wrong.
After all, you printed the sizes and aren't those numbers.


http://www.eelis.net/iso-c++/testcase.xhtml
Make sure your testcase is self-contained and actually reproduces the problem
(...)
A testcase consisting of randomly copy&paste'd bits of code that you thought were relevant can obviously not reproduce the problem.

Topic archived. No new replies allowed.