I think that in later projects I'll switch to the STL but for now I'm more comfortable with qsort() - Thanks for your patiance.
I'm sorry to keep bugging you with this qsort but I got one more problem:
I have a class:
class player_group{public: player_group(); unit units[10]; unit mid_pos; grid main_path[500]; ... int CompareDis(struct unit *elem1, struct unit *elem2); int CompareDisMid(struct unit *elem1, struct unit *elem2); void SortUnits(int method); ...};
and the funcs:
int player_group :: CompareDis(struct unit *elem1, struct unit *elem2) { if(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)) return -1; else if (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)) return 1; else return 0; }int player_group :: CompareDisMid(struct unit *elem1, struct unit *elem2) { if(abs(elem1->current_step.x-mid_pos.current_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)) return -1; else if(abs(elem1->current_step.x-mid_pos.current_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)) return 1; else return 0; }void player_group :: SortUnits(int method){ if(method==0) { qsort((void *) &units, number_of_units, sizeof(struct unit), (compfn)CompareDis ); } if(method==1) { qsort((void *) &units, number_of_units, sizeof(struct unit), (compfn)CompareDisMid ); }}
This is supposed to sort the units in a group by one of the methods. When I try to compile I get the error: "no matches converting CompareDis to type int"
same for the CompareDisMid. What is the problem?
Thanks a lot to everyone!
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky