When looking at Apue Figure1.10 found signal (SIGINT, sig_int) here Sig_int directly with the function name, but see Thinking-in-c++ vol.2 when found Mem_fun (&shape:: Draw) But the function name to take the address operation, feel in doubt to check the information, the following code can show some of the differences between the two
Resources:
Http://stackoverflow.com/questions/3050805/pointer-to-const-member-function-typedef
http://www.cplusplus.com/reference/functional/mem_fun1_t/
Http://www.cnblogs.com/taobataoma/archive/2007/08/30/875743.html
http://www.cplusplus.com/reference/functional/mem_fun/
Code:
1#include <functional>2#include <iostream>3#include <algorithm>4 5 6 using namespacestd;7 8 voidMyintArg);9 Ten classMyClass One { A Public: - voidMyintArg) {cout << arg <<Endl;} - }; the - //Method - -typedefvoidFunc_ptr (int);//Func_ptr and func_ptr2 nature is the same, choose which way of definition to see your preferences +typedefvoid(*FUNC_PTR2) (int);//Reference:http://www.cnblogs.com/qrlozte/p/4439002.html - voidDosomething_one (func_ptr ptr); + voiddosomething_two (func_ptr2 ptr); A at //Method 3,4,5 - - voidDosomething_three (void(MyClass::* my_ptr) (int)); - -typedefvoidFunctype (int); -typedef functype MYCLASS::*Myclassfunctype; in -typedefvoid(MyClass::* memberfunctype) (int); to + voiddosomething_four (Myclassfunctype ptr); - the voiddosomething_five (Memberfunctype ptr); * $ Panax Notoginseng - intMain () { the /* + the essence of the method is the same. A Method 3,4,5 Nature is the same the */ + Dosomething_one (my); - Dosomething_two (my); $Dosomething_three (&myclass::my); $Dosomething_four (&myclass::my); -Dosomething_five (&myclass::my); - return 0; the}///:~ - Wuyi voidMyintArg) the { -cout << Arg <<Endl; Wu } - About $ voidDosomething_one (func_ptr ptr) - { -ptr1); - } A + voiddosomething_two (func_ptr ptr) the { -ptr2); $ } the the voidDosomething_three (void(MyClass::* my_ptr) (int)) the { theMyClass *obj =NewMyClass; -(OBJ->*MY_PTR) (3); in Deleteobj; the } the About voiddosomething_four (myclassfunctype ptr) the { theMyClass *obj =NewMyClass; the(OBJ->*PTR) (4); + Deleteobj; - } the Bayi voiddosomething_five (memberfunctype ptr) the { theMyClass *obj =NewMyClass; -(OBJ->*PTR) (5); - Deleteobj; the}
The difference between C pointer-to-function and C + + Pointer-to-memberfunction