This is called a functor (not to be confused with a functor in functionnal programming languages).
It mimics a function and can be used as such in functions from the standard library :
std::vector<Result> collection;
// fill with data
// Sort according to the () operator result
sortResults sort;
std::sort(collection.begin(), collection.end(), sort);
A nice advantage compared to simple functions, is that it can hold a state, variable, etc. You can make a parallel with closures (if that rings a bell)
struct GreaterThan{
int count;
int value;
GreaterThan(int val) : value(val), count(0) {}
void operator()(int val) {
if(val > value)
count++;
}
}
std::vector<int> values;
// fill fill fill
GreaterThan gt(4);
std::for_each(values.begin(), values.end(), gt);
// gt.count now holds how many values in the values vector are greater than 4