|
1 #include <unistd.h> 2 #include <stdlib.h> 3 #include <stdio.h> 4 #include <string.h> 5 6 typedef void (*func_type)(void * obj, int num); 7 class test_t 8 { 9 public: 10 void test_func(int num) 11 { 12 printf("num is %d\n", num); 13 } 14 15 int a; 16 int b; 17 18 }; 19 20 21 int main(int argc, char* argv[]) 22 { 23 test_t obj; 24 func_type p = &test_t::test_func; 25 for(int i = 100; i < 104; i++) 26 p(&obj, i); 27 28 return 0; 29 } 30
程序比较简单,注意它的编译参数: g++ -Wno-pmf-conversions -O hello.cpp && ./a.out 否则编译不能通过。
|