龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

C++基础:函数指针调用方式[组图]

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
  // test12.cpp : Defines the entry point for the console application.
    //
  
    #include "stdafx.h"
  
    void func(int i)
    {
    printf("This is for test %i ", i);
    }
  
   <!-- frame contents -->
<!-- /frame contents -->   typedef void (*PFUNC)(int);
  
     strUCt FUNC
    {
    PFUNC pfunc;
    };
   
    void callfunc(void pfunc(int), int i)
    {
    pfunc(i);
    }
  
    int main(int argc, char* argv[])
    {
    void (*pfunc)(int);
    pfunc = &func;
    pfunc(1);
  
    callfunc(pfunc, 2);
  
    FUNC sfunc;
    sfunc.pfunc = &func;
    sfunc.pfunc(3);
  
    return 0;
    }
   
  
  
   更多内容请看C/C++技术专题专题,或
  
精彩图集

赞助商链接