Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a regular function call, and therefore it can be used in templates instead of a pointer to a function.
In the case of binary function objects, this operator() member function takes two parameters.
binary_function is just a base class, from which specific binary function objects are derived. It has no operator() member defined (derived classes are expected to define this) - it simply has three public data members that are typedefs of the template parameters. It is defined as:
| 1 2 3 4 5 6 |
|
Members
- first_argument_type
- Alias of the first template parameter, which is the type for the first argument in member operator().
- second_argument_type
- Alias of the second template parameter, which is the type for the second argument in member operator().
- result_type
- Alias of the third template parameter, which is the return type in member operator().
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Possible output:
Please enter first number: 2 Please enter second number: 33 Numbers 2 and 33 are not equal. |
See also
| unary_function | Unary function object base class (class template) |
