I have a Point
class where I create each object by doing Point p(a, b)
and I want to find whether the Point exists in a vector that I declared as vector<Point> vPoint
.
A segment of my code is as follows;
Point p(a, b);
vector<Point>::iterator it = find(vPoint.begin(), vPoint.end(), p);
if(it != vPoint.end())
{
// do something
}
The error message I get is as follows; In file included from
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:439:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:846:22: error:
invalid operands to binary expression ('Point' and 'const Point')
if (*__first == __value_)
~~~~~~~~ ^ ~~~~~~~~
segmentpoints.cpp:72:33: note: in instantiation of function template specialization 'std::__1::find<std::__1::__wrap_iter<Point
*>, Point>' requested here
vector<Point>::iterator it = find(vPoint.begin(), vPoint.end(), p);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/utility:403:1: note:
candidate template ignored: could not match 'pair<type-parameter-0-0, type-parameter-0-1>' against 'Point'
operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:574:1: note:
candidate template ignored: could not match 'reverse_iterator<type-parameter-0-0>' against 'Point'
operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:866:6: note:
candidate template ignored: could not match 'istreambuf_iterator<type-parameter-0-0, type-parameter-0-1>' against 'Point'
bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
So I wonder whether this issue is due to not using pointers when creating objects/ iterator not supporting objects that are not pointed by pointers, or something else.