博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

os fans

MSN & Mail:jinglexy at yahoo dot com dot cn
操作系统开发博客圈:http://blog.chinaunix.net/group/group_507.html
qq group(os fans): 3*2*2*6*2*9*2
  jinglexy.cublog.cn

关于作者
马甲:天衣有缝
职业:linux driver
位置:徐家汇上海交大
|| << >> ||
我的分类


c++普通成员函数转换成c函数指针的执行(原创)
  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
否则编译不能通过。

发表于: 2008-05-24,修改于: 2008-05-25 13:09,已浏览233次,有评论0条 推荐 投诉


网友评论
 发表评论