[EDIT2] Fix the '->' to '.'.
*note*:
1. Your SortDis and SortDisMid are classes.
2. Putting () behind both will create another new instance of the class. That way you are operating on some temporary-created-instance instead of your real object. That's why your stuff never get sorted. Further calling might screw up the stack and causes weird problems. And Your operator() overload hides your mistake.
I suggest you do this way:
class player_group{public: static bool SortDis( unit const & elem1, unit const & elem2); static bool SortDisMid( unit const & elem1, unit const & elem2);};bool player_group::SortDis(unit const & elem1, unit const & elem2){ return abs(elem1.next_step.x-main_path[place_on_path+step].x)+ abs(elem1.next_step.y-main_path[place_on_path+step].y) < abs(elem2.next_step.x-main_path[place_on_path+step].x)+ abs(elem2.next_step.y-main_path[place_on_path+step].y); }bool player_group::SortDisMid(unit const & elem1, unit const & elem2){ return abs(elem1.current_step.x-mid_pos.urrent_step.x)+ abs(elem1.current_step.y-mid_pos.current_step.y) < abs(elem2.current_step.x-mid_pos.current_step.x)+ abs(elem2.current_step.y-mid_pos.current_step.y); }void player_group::SortUnits(int method){ if(method==0) { sort(units.begin(), units.end(), SortDis); } if(method==1) { sort(units.begin(), units.end(), SortDisMid); }}
[Edited by - DerekSaw on February 10, 2006 2:22:27 AM]