C ++ operator overload: stl sort on my custom class vector

I have a very simple class that is stored inside STL Vector. I try to sort this vector, but I get cryptic STL errors. Can anyone help?

// Point.h
class Point {
public:
  Point() : x(0), y(0) {}
  Point( float x0, float y0 ) : x(x0), y(y0) {}
  float x;
  float y;
};

// Point.cpp, updated const as per given answers
bool operator< (const Point &p1,const  Point &p2)
{
    return p1.x < p2.x || (p1.x==p2.x && p1.y< p2.y);
}

Again, this Point class is stored in a vector and sorted:

std::vector<Point> tmp=N->points;
std::sort(tmp.begin(),tmp.end());

Errors:

http://ideone.com/WIv0u

Can someone point me in the right direction? Thank!

+3
source share
1 answer

bool operator< ( const Point &p1, const Point &p2 )

+6
source

All Articles