J
Jim Bancroft
I'm trying to roll a custom sort routine for an STL list. This list is a
member of one of my classes, and I'd like my custom sort to use another
class member in its calculations. However, I'm having trouble figuring out
if / how I can do this.
I've read this page about how to create a custom sort routine:
http://www.cplusplus.com/reference/stl/list/sort.html
However, in the example given the custom sort routine doesn't belong to a
particular class. When I created my own sort routine, as part of my class,
the compiler complains about my function call missing an argument list,
which sounds to me like the compiler simply doesn't like sort routines to be
part of a class--maybe I'm wrong.
This is what my custom sort routine's signature looks like:
bool Player::compare_verticies (Point first, Point second)
I call it like this, from within a class method in the "Player" class:
list<Point> pointList;
//populate list....
pointList.sort(compare_verticies);
The compiler tells me that "Player::compare_clockwise_verticies': function
call missing argument list; use '&Player::compare_clockwise_verticies' to
create a pointer to member".
I really need to refer to the class member in my custom sort routine, but I
don't see how I can do it if sort routines must be non-class methods. Does
anyone know what I can try here? Thanks very much.
member of one of my classes, and I'd like my custom sort to use another
class member in its calculations. However, I'm having trouble figuring out
if / how I can do this.
I've read this page about how to create a custom sort routine:
http://www.cplusplus.com/reference/stl/list/sort.html
However, in the example given the custom sort routine doesn't belong to a
particular class. When I created my own sort routine, as part of my class,
the compiler complains about my function call missing an argument list,
which sounds to me like the compiler simply doesn't like sort routines to be
part of a class--maybe I'm wrong.
This is what my custom sort routine's signature looks like:
bool Player::compare_verticies (Point first, Point second)
I call it like this, from within a class method in the "Player" class:
list<Point> pointList;
//populate list....
pointList.sort(compare_verticies);
The compiler tells me that "Player::compare_clockwise_verticies': function
call missing argument list; use '&Player::compare_clockwise_verticies' to
create a pointer to member".
I really need to refer to the class member in my custom sort routine, but I
don't see how I can do it if sort routines must be non-class methods. Does
anyone know what I can try here? Thanks very much.