# Include <iostream> # include <functional>
// STD: bind returns the function object void fun1 (int A, int B) {STD: cout <A <B <STD: Endl ;} using namespace STD: placeholders; Class A {public: void fun2 (int A, int B) {STD: cout <A <B <STD :: endl ;}; int main () {// first usage, bind the real parameter STD: BIND (fun1, 1, 2 )(); // during the call, copy 1 and 2 is passed as the real parameter to fun1. The bound parameters in the BIND must be the same as the number of parameters called by fun1, the parameter will be passed to fun1 as the input parameter // placeholder _ 1, and the positive parameter STD: BIND (fun1, _ 2, _ 1) will be accepted only when the function is called) (1, 2); // The placeholder name indicates the order in the call type. This indicates fun1 (2, 1) // bind the member function a A; STD :: BIND (& A: fun2, A, _ 1, _ 2) (3, 4 ); // you need to pass something similar to this pointer so that this function object can be called & you must add // functon usage. The most common usage can store the results returned by bind and callback when needed later, is a callback mechanism STD: function <void (INT, INT)> func; // function can store function pointer objects. Previously, it was assumed that only STD: bind func = fun1 can be stored; func (5, 6); // function calls a member function // 1. in the function, write the class name STD: function <void (A &, Int, INT)> fun1; // you can assign a value to int. The Int returns the void member function fun1 = STD:: BIND (& A: fun2, _ 1, _ 2, _ 3); fun1 (A, 8, 9); // 2. write a class instance in the bind. This method is mostly STD: function <void (INT, INT)> fun2; fun2 = STD: BIND (& A: fun2,, _ 1, _ 2); fun2 (9, 10); getchar (); Return 0 ;}