18 Function Objects & 19Command Mode 20 Function Objects Application in STL

xiaoxiao2021-03-05  24

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.

转载请注明原文地址:https://www.9cbs.com/read-36129.html

New Post(0)