I have a class called getout (no constructor). Within that class I have some private variables that are priority queues. The priority queues are initialized with a custom comparator function that I am supposed to create:
priority_queue<tile, vector<tile>, ****insert comparator here***> primary;
I understand that custom comparators can be written using a class or struct. However I cannot do it this way (Im sure there's a way). The reason why is within this comparator I use functions pertaining to my class getout. I decided to write my comparator as a regular bool function as follows:
//comparator less_than
bool less_than(const tile &t1, const tile &t2)
{
if(t1.rubble_amount == t2.rubble_amount){
if(get_col(t1.index) == get_col(t2.index)){
return get_row(t1.index) > get_row(t2.index);
}
else if(get_col(t1.index) > get_col(t2.index)){
return true;
}
}//if
return t1.rubble_amount > t2.rubble_amount;
}//comparator less_than
The functions pertaining to my class I am using are get_row(), get_col(). I do not want to resolve this by making them member variables of my tile structs.
How do I define the comparator of my priority queue that is of the form of a bool function?
Everything is in my class getout.
I have tried:
priority_queue<tile, vector<tile>, function<bool(tile, tile)>> primary(less_than);
But I am getting an error "Unknown type name less_than". Am I implementing the above code correctly ? Is there another way I can do this?
(all necessary libraries are included)
Thanks!!
Aucun commentaire:
Enregistrer un commentaire