I’m a relatively experienced programmer, coming back into some C++ review for a class. We have an assignment to write a couple relatively simple c++ programs. Getting an odd error that I’m not used to, but I’m sure it’s child’s play for this community.
int pull_next_element (int r, std::vector<int>& sequence) {
int x = sequence[0];
sequence.erase(sequence.begin()); //orig: sequence.erase(0);
return x;
}
Error I was getting:
Error C2664: 'std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)' : cannot convert parameter 1 from 'int' to 'std::_Vector_const_iterator<_Myvec>'
EDIT: Replaced with iterator instead of numerical index, and otherwise fixed this problem throughout the code. Thanks everyone.
You should use reference argument instead of value argument of ‘sequence’, or your erase will be useless.