Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top