Comparator for use with sort
c++, visual-c++
Solution
You need to make your member function static in order to be accessible by `sort`. In your class header, please declare it as such:
`static bool QueryEvaluatorPrivate::clauseComparator(const QueryClause & cl1, const QueryClause & cl2);`
There is no need to use `bind`, as your comparator most likely (or shouldn't) have any need to access class members.
Problem
I was looking at http://www.cplusplus.com/reference/algorithm/sort/ and want to implement something similar: I defined a function `clauseComparator` which is like `myfunc` given in the example in the link provided. ``` bool QueryEvaluatorPrivate::clauseComparator(QueryClause cl1, QueryClause cl2) { int priority1 = clausePriority(cl1), priority2 = clausePriority(cl2); return priority1 < priority2; } ``` and I used it like: ``` sort(clauses.begin(), clauses.end(), clauseComparator); ``` But VS complains: ``` Error 4 error C3867: 'QueryEvaluatorPrivate::clauseComparator': function call missing argument list; use '&QueryEvaluatorPrivate::clauseComparator' to create a pointer to member h:\dropbox\sch\cs3202\code\source\query\query evaluator\queryevaluator.cpp 138 Error 5 error C2780: 'void std::sort(_RanIt,_RanIt)' : expects 2 arguments - 3 provided h:\dropbox\sch\cs3202\code\source\query\query evaluator\queryevaluator.cpp 138 ``` Firstly whats wrong (missing arg list)? I tried following the suggestion given in the error to add `&` and ended up with ``` Error 4 error C2276: '&' : illegal operation on bound member function expression h:\dropbox\sch\cs3202\code\source\query\query evaluator\queryevaluator.cpp 138 Error 5 error C2780: 'void std::sort(_RanIt,_RanIt)' : expects 2 arguments - 3 provided h:\dropbox\sch\cs3202\code\source\query\query evaluator\queryevaluator.cpp 138 ``` Whats wrong here? In my understanding, it should pass a function pointer which I understand should be accepted by `sort` too?