If the class is overloaded with the function call operator, we can use the class object like using the function. Because such classes can also store states, they are more flexible than common functions.
For example:
Struct absint {int operator () (INT Val) const {return Val <0? -Val: Val ;}}
This class only defines one operation: the function call operator, which accepts an int type real parameter and returns the absolute value of the real parameter.
We use the call operator to make an absint object act on a real parameter list. This process looks like a function call process:
Int I =-42; absint absobj; int UI = absobj (I); // pass I to absobj. Operator ()
Even if absobj is just an object rather than a function, we can "call" this object. The call object is actually running the overloaded call operator. In this example, the operator accepts an int value and returns its absolute value.
Note: The function call operator must be a member function. A class can define multiple call operators of different versions, which are different in the number or type of parameters. (Heavy Load)
If a class defines the call operator, the class object is called a function object. Because we can call such an object, all of them say that these objects are "behave like functions ".
Function object class with status
Like other classes, function object classes can contain other members besides operator. Function object classes usually contain some data members who are used to customize the operations in call operators.
Function call operator overload