回调函数实现的实现动态绑定
来源:互联网 发布:ubuntu 软件安装器 编辑:程序博客网 时间:2024/06/09 19:40
// CallBackApp.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
typedef void(*pcb)(char *);
void GetCallBack(pcb callback)
{
/*do something*/
char buffer[] = "hello world!";
callback(buffer);
}
void CallbackFun1(char *s)
{
/* do something */
cout<<s<<endl;
cout<<"call CallbackFun1!"<<endl;
}
void CallbackFun2(char *s)
{
/* do something */
cout<<s<<endl;
cout<<"call CallbackFun2!"<<endl;
}
void CallbackFun3(char *s)
{
/* do something */
cout<<s<<endl;
cout<<"call CallbackFun3!"<<endl;
}
pcb funArray[3] = {CallbackFun1,CallbackFun2,CallbackFun3};
int _tmain(int argc, _TCHAR* argv[])
{
for(int i=0;i<3;i++)
{
GetCallBack(funArray[i]);
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
typedef void(*pcb1)(char *);
typedef void(*pcb2)(long value);
typedef void(*pcb3)(string str);
struct Funtion
{
pcb1 f1;
pcb2 f2;
pcb3 f3;
}myFun;
void GetCallBack(Funtion fun)//(pcb1 callback)
{
/*do something*/
char buffer[] = "hello world!";
//callback(buffer);
fun.f1(buffer);
}
void CallbackFun1(char *s)
{
/* do something */
cout<<s<<endl;
cout<<"call CallbackFun1!"<<endl;
}
void CallbackFun2(char *s)
{
/* do something */
cout<<s<<endl;
cout<<"call CallbackFun2!"<<endl;
}
void CallbackFun3(char *s)
{
/* do something */
cout<<s<<endl;
cout<<"call CallbackFun3!"<<endl;
}
pcb1 funArray[3] = {CallbackFun1,CallbackFun2,CallbackFun3};
int _tmain(int argc, _TCHAR* argv[])
{
Funtion myFuntion;
for(int i=0;i<3;i++)
{
myFuntion.f1 = funArray[i];
GetCallBack(myFuntion);
}
return 0;
}
- 回调函数实现的实现动态绑定
- 动态库DLL回调函数实现
- 什么是回调函数?回调函数的简单实现。
- 回调函数实现
- ICallbackEventHandler:回调函数的实现(备忘)
- 简单的回调函数实现
- 回调函数的作用与实现
- 回调函数的作用与实现
- 回调函数的作用与实现
- python异步回调函数的实现
- java回调函数的简单实现
- PHP回调函数的实现方法
- PHP回调函数的实现方法
- PHP回调函数的实现方法
- java中回调函数的实现
- Android实现自己的回调函数
- Jquery实现自己的回调函数
- c++中的回调函数的实现
- Failed to create the Java Virtual Machine 解决方法
- 【JMX】JMX心得
- JAVA常用快捷键
- Linux Command Line 详细解析
- SIP中的早期媒体early media与回铃
- 回调函数实现的实现动态绑定
- 键盘输入数字,自动排序后输出
- 系统进程详解
- ora-01555 模拟及解决
- 用java来实现c#中的一些类和方法
- java 环境变量配置
- linux平台设备驱动
- 什么是领域驱动设计(Domain Driven Design)?
- 用windbg分析蓝屏文件minidump随记!!