This question already has an answer here:
- Operator overloading 6 answers
Based on this:
How to find an item in a std::vector?
C++ Erase vector element by value rather than by position?
I created this code:
class Challenge{
}
class App{
private:
std::vector<Challenge> challenges;
public:
void CheckChallenges();
}
void App::CheckChallenges(){
Challenge challenge;
if(std::find(challenges.begin(),challenges.end(),challenge)==challenges.end())return false;
challenges.erase(std::remove(challenges.begin(),challenges.end(),challenge),challenges.end());
}
Either the line with std::find or line with std::remove prints similar error:
/usr/include/c++/4.9/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Iter_equals_val<_Value>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<Challenge*, std::vector<Challenge> >; _Value = const Challenge]’:
/usr/include/c++/4.9/bits/stl_algo.h:120:22: required from ‘_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Challenge*, std::vector<Challenge> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const Challenge>]’
/usr/include/c++/4.9/bits/stl_algo.h:162:43: required from ‘_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator<Challenge*, std::vector<Challenge> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const Challenge>]’
/usr/include/c++/4.9/bits/stl_algo.h:3779:50: required from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<Challenge*, std::vector<Challenge> >; _Tp = Challenge]’
...
/usr/include/c++/4.9/bits/predefined_ops.h:191:17: error: no match for ‘operator==’ (operand types are ‘Challenge’ and ‘const Challenge’)
{ return *__it == _M_value; }
Could someone explain me what's wrong?
Aucun commentaire:
Enregistrer un commentaire