I wrote myself a compare function for sort(). It worked well when I put it this way.
bool comp(string a, string b)
{
...;
}
int main()
{
sort(...,...,comp);
}
However, when I put all this inside a class, say:
class Test {
public:
bool comp(string a,string b)
{
...;
}
vector <string> CustomSort(vector <string> str) {
sort(...,...,comp);
}
};
There is a compile error "No matching function for call to 'sort ......'.
Why would this happen?
bool comp(const string &a, const string &b), I think. It doesn't affect the name lookup, but it surely affects the runtime efficiency (constructing and then destroying a new string for each argument on each comparison is relatively expensive).