Think about how you call compareFuncoutside the class. You will always have something like
a.compareFunc(b, c)
^ ^ ^
which is 3 parameters, not 2.
sort the code is outside your class and will have to use the syntax above.
Creating a static element allows this call:
Solution::compareFunc(a, b)
which is only 2 parameters and matches the expected predicate std::sort.
(), operator< -, , , :
struct Foo
{
bool operator<(Foo const& other) { }
};
int main()
{
Foo a, b;
a < b;
}
struct Foo
{};
bool operator<(Foo const& lhs, foo const& rhs) { }
int main()
{
Foo a, b;
a < b;
}