背景: #EDF0F5 #FAFBE6 #FFF2E2 #FDE6E0 #F3FFE1 #DAFAF3 #EAEAEF 默认  
阅读新闻

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

[日期:2005-12-29] 作者: [字体: ]
  // 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 = &func;
  pfunc(1);

  callfunc(pfunc, 2);

  FUNC sfunc;
  sfunc.pfunc = &func;
  sfunc.pfunc(3);

  return 0;
  }
 




阅读:
打印