1、定义
1)声明函数指针类型
typedef int(*CallBackFunction)(int a, int b);
2)定义函数指针对象
CallBackFunction CallBackFunction_PTR;
3)初始化函数指针对象
void set_call_back(CallBackFunction cbf)
{
CallBackFunction_PTR = cbf;
}
4)定义实现函数
int add_test(int a, int b)
{
return a + b;
}
2、完成代码
#include <iostream> typedef int(*CallBackFunction)(int a, int b); CallBackFunction CallBackFunction_PTR; void set_call_back(CallBackFunction cbf) { CallBackFunction_PTR = cbf; } int add_test(int a, int b) { return a + b; } int main() { set_call_back(add_test); std::cout << CallBackFunction_PTR(5, 6); std::cout << "\r\n"; system("pause"); }
标签:set,cbf,函数,int,back,初识,CallBackFunction,回调,PTR From: https://www.cnblogs.com/missyou0813/p/17851595.html