I have a function which searches an STL container then returns the iterator when it finds the position, however I am getting some funny error messages, can tell me what I am doing wrong?
Function:
std::vector< CClass >::iterator CClass::SearchFunction( const std::string& strField ) { ... return it; ... }
Error:
error C2664: 'std::_Vector_iterator<_Ty,_Alloc>::_Vector_iterator(const std::_Vector_iterator<_Ty,_Alloc> &)' : cannot convert parameter 1 from 'std::_Vector_const_iterator<_Ty,_Alloc> *__w64 ' to 'const std::_Vector_iterator<_Ty,_Alloc> &'
Your search function is returning a const_iterator. You should either return the same type, i.e.
std::vector< CClass >::const_iterator, or cast it to astd::vector< CClass >::iteratorif you intend the caller to be able to modify the found item through the iterator.EDIT: after seeing your update, it seems the problem is your iterator (it) has a different type than your function return. They should be the same.