3
4

1 回答 1

4

You are the victim of object slicing.

When you assign less<T> or greater<T> to the binary_function type, the operator() they define is gone.

From my favorite reference:

binary_function does not define operator(); it is expected that derived classes will define this. binary_function provides only three types - first_argument_type, second_argument_type and result_type - defined by the template parameters.

You should pass less<T> or greater<T> in directly. You can also use pointer_to_binary_function, but they've both been deprecated in C++11 in favor of function.

于 2012-10-20T00:43:06.740 回答