I am working on a program to insert objects into vector of objects only if it does not exist already keeping them sorted. so for that i have included algorithm header and using find and sort functions i am trying to execute the same but it is giving me an error I am not able to understand and solve.
This is the function for insertion where it is returning a an object of class word and data is a vector of words.
Word *WordVector::insert(const string text){
Word newWord(text);
if(data.size()==0)
{
data.push_back(newWord);
}
else{
if(find(data.begin(),data.end(),newWord)!=data.end()){
newWord.increaseCount();
}
else data.push_back(newWord);
std::sort(data.begin(), data.end());
}
return &newWord;
}
and it gives me this error "Invalid operands to binary expression ('Word' and 'const Word')" in algorithm file at this method at line 7
template <class _InputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_InputIterator
find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
for (; __first != __last; ++__first)
if (*__first == __value_)
break;
return __first;
}