Joseph
Joseph

Reputation: 13188

C++ Operator overload: stl sort on vector of my custom class

I have a very basic class that is stored inside an STL Vector. I am trying to sort that vector, but am getting cryptic STL errors. Can someone assist?

// 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 is being 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? Thanks!

Upvotes: 3

Views: 7800

Answers (1)

Benjamin Lindley
Benjamin Lindley

Reputation: 103713

bool operator< (constPoint &p1,constPoint &p2 )

Upvotes: 6

Related Questions