i have code like this
priority_queue<int, std::vector<int>, decltype(&VD::CompareByDistance)> pqDistances(&VD::CompareByDistance);
where
class VD
{
...
bool CompareByDistance(int indexLeft, int indexRight) const;
};
But i get error
error C2064: term does not evaluate to a function taking 2 arguments
How can i pass class member as a compator, the thing is that i want comparator to access its instance fields. Thanks.
takes three arguments: The
this
-pointer and the bothint
s.Besides this being the wrong number of arguments for the
priority_queue
template parameter: What instance ofVD
do you expect this non-static method to be called on?A workaround for this would be "carrying" the instance with you like this:
This
comp
object would now be a valid template argument for your queue. For example: