Algorithm by C/C++ : Callback function
来源:互联网 发布:淘宝美瞳店铺哪个好 编辑:程序博客网 时间:2024/06/05 03:29
1. general description
Developers are often confused by what a callback function is because of the name of the thing.
A callback function is a function which is:
①. passed as an argument to another function
②. invoked after some kind of event.
Once its parent function completes, the function passed as an argument is then called.
The so-called callback, is the module A through a function B() to complete a certain function, but the function a() is the callback function.
The definition of the callback function pointer is defined in module B, and the registration function is also implemented.
2. Demo and Codes
#include <stdio.h> typedef void (*CallBackFun)(int p); typedef void (*CallBackMessage)(void); void PrintNum(int n); void ShowNum(int n,CallBackFun x); void ShowMessage(CallBackMessage x);void PrintMessage1(); void PrintMessage2(); void PrintMessage3(); int main(){ ShowNum(11111,PrintNum); ShowNum(22222,PrintNum); ShowMessage(PrintMessage1); ShowMessage(PrintMessage2); ShowMessage(PrintMessage3); } void PrintNum(int n){ printf("Test1 is called,the number is %d\n",n); } void ShowNum(int n,CallBackFun x){ x(n);} void PrintMessage1(){ printf("This is the message 1!\n"); } void PrintMessage2(){ printf("This is the message 2!\n"); } void PrintMessage3(){ printf("This is the message 3!\n"); } void ShowMessage(CallBackMessage x){ x();}
Author:Kyrie
0 0
- Algorithm by C/C++ : Callback function
- C callback function example
- CallBack function from Pointers on C
- callback c
- A simple exmaple of CallBack function in C
- C语言中的回调函数(Callback Function)
- C语言中的回调函数(Callback Function)
- C Function
- c-function
- callback function
- CallBack Function
- Callback function
- callback function
- Callback Function
- callBack function
- Callback Function
- callback function
- callback function
- iOS开发网络篇—文件下载(暂停和恢复)
- 机器学习 第五天 17/03/31
- 进阶过程之简单工厂模式
- Python-Image 基本的图像处理操作
- UVA-10815
- Algorithm by C/C++ : Callback function
- Android UncaughtExceptionHandler 解决未捕获异常,防止软件报”停止运行“
- Caffe
- Qt2D绘图详解
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
- 开源网站收集
- 分布式--CentOS安装zookeeper(单机版)
- 拷贝函数的选取,极其sizeof()运算符的注意事项及其实例
- rdo安装openstack