I have made a class called Point which simply contains a tuple of x y coordinates. I also made a vector of the Type Point and added the point (3,4). Now i want to search this vector for the point with binary search, and if it return true then i want to print "yes", to confirm that the point exists in the vector. Unfortunately, the find function doesnt work on a vector of type Point, how can fix this?
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Point {
private:
double xval, yval;
public:
// Constructor uses default arguments to allow calling with zero, one,
// or two values.
Point(double x = 0.0, double y = 0.0) {
xval = x;
yval = y;
}
// Extractors.
double x() { return xval; }
double y() { return yval; }
};
int main()
{
vector<Point> points;
points.push_back(Point(3,4));
if (binary_search(points.begin(),points.end(),Point(3,4)))
{cout<<"The point exists"<<endl;}
return 0;
}