문제

I have the following vector:

const vector<tuple<int,int>> &v;

I want to add tuples to this vector, so I did the following:

tuple<int,int> newOne = make_tuple(0,2);
v.push_back(newOne);

The error message I got was:

"No matching member function for call to 'push_back'"

I cannot see what I did wrong. Can anyone tell me why this is wrong and how to fix it?

도움이 되었습니까?

해결책

When you take a parameter as a const reference it's a reference to a non-mutable object. If you can change the parameter to just a reference you should be able to add more elements.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top