Item 18. Function ObjectsItem 19. Commands and HollywoodItem 20. STL Function Objects
1. What function objects are very scary, it is not mysterious, it is also a class object, but the class overloads the operator () so that the object is the same as the function. Class Fib {Public: FIB (): A0_ (1), A1_ (1) {} int operator (); private: int A0_, a1 _;}; int FIB :: Operator () {INT TEMP = A0_; A0_ = A1_ A1_ = Temp A0_; return temp;}
FIB FIB; int x = fib (); // is equivalent to calling Fib.Operator ()
2. The Commands mode uses a function object as a callback, ie the function object is transmitted to another function, and the method of calling a function object in that function.
3. Many algorithms in the application STL in the STL are used to function objects.