快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

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 = &func;
  pfunc(1);

  callfunc(pfunc, 2);

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

  return 0;
  }
顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论