c++ - Define Operator < in struct for 2 objects of another struct -


i have little problem in c++ , hope able me out.

i want define struct mypoint. struct should able compare 2 objects type point (defined pair). want every "instance" of mypoint able compare 2 points on own. tried code:

typedef pair<int,int> point; struct mypoint{     point p;     inline bool operator<( point x, point y ){     return !ccw(p,x,y); } 

so every mypoint should consider own point p while comparing 2 points x,y. (translated) error is

"error c2804:  binary operator '<' has arguments/parameters" 

it seems it's syntacticly possible make operator 1 point, guess compare point mypoint, that's not should be. background of problem want use predefined sort function sort vector of points , sorting "function" want deliver mypoint object.

i think (maybe) trying write functor

struct mypoint {     mypoint(point p) { this->p = p; }     bool operator()(point x, point y) const     {         return !ccw(p,x,y);     }     point p; }; 

a functor can passed third argument std::sort.

std::sort(vec.begin(), vec.end(), mypoint(p)); 

i have doubts though, assuming ccw means counterclockwise don't think valid sort condition.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -