SIGN IN SIGN UP
2019-07-21 11:41:27 +08:00
/**
* @file func_pointer.cpp
* @brief 函数指针的使用!
* @author 光城
* @version v1
* @date 2019-07-20
*/
#include <iostream>
2019-07-21 11:41:27 +08:00
using namespace std;
/**
* @brief
* 定义了一个变量pFun这个变量是个指针指向返回值为空和参数为int的函数的指针
2019-07-21 11:41:27 +08:00
*/
void (*pFun)(int);
2019-07-21 11:41:27 +08:00
/**
* @brief 代表一种新类型不是变量所以与上述的pFun不一样
*/
typedef void (*func)(void);
2019-07-21 11:41:27 +08:00
void myfunc(void) { cout << "asda" << endl; }
2019-07-21 11:41:27 +08:00
void glFun(int a) { cout << a << endl; }
int main() {
func pfun = myfunc; /*赋值*/
pfun(); /*调用*/
pFun = glFun;
(*pFun)(2);
2019-07-21 11:41:27 +08:00
}