C++基础:函数指针调用方式

// test12.cpp : Defines the entry point for the console application.
  //

  #include "stdafx.h"

  void func(int i)
  {
  printf("This is for test %i\r\n", i);
  }

  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 = %26amp;func;
  pfunc(1);

  callfunc(pfunc, 2);

  FUNC sfunc;
  sfunc.pfunc = %26amp;func;
  sfunc.pfunc(3);

  return 0;
  }

 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 您可能对 [C & C++] 的这些文章也感兴趣:

Ogre新加FrameListener.frameRenderingQueued分析
C++中的函数重载
轻轻松松C to C++ (二)
JAVA和C++区别
C语言中的面向对象(4)-面向对象思想
C++数据结构学习:二叉树(3)
C++中建立对象间消息连接的系统方法
C语言程序设计基础之枚举与位运算
PE文件格式详解(2)
C++数据结构学习:递归(3.1)