• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
thankgoodness
博客园    首页    新随笔    联系   管理    订阅  订阅

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
posted @ 2009-04-17 10:28  宇晨  阅读(582)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3