回调函数
来源:互联网 发布:ubuntu虚拟机镜像文件 编辑:程序博客网 时间:2024/06/05 15:22
#include <iostream>
using namespace std;
typedef void (*CALLBACK)( int a, int b );
class CBase
{
public:
CBase();
public:
/*
** 注册回调函数
**
*/
void RegisterCallback( CALLBACK fun, int k, int j );
/*
** 调用回调函数
**
*/
void CallCallback();
private:
/*
** 成员变量:
** 分别保存回调函数指针
** 回调函数中的形参参数
**
*/
int m;
int n;
CALLBACK func;
};
CBase::CBase()
{
func = NULL;
}
void CBase::RegisterCallback( CALLBACK fun, int k, int j )
{
func = fun;
m = k;
n = j;
return;
}
void CBase::CallCallback()
{
func( m, n );
return;
}
//////////////////////////////////////////////////////////////////////////
// 函数1
void fun1( int a, int b )
{
cout << "fun1 is called" << endl;
cout << a << " " << b << endl;
cout << "*****************" << endl;
return;
}
//////////////////////////////////////////////////////////////////////////
class CCall
{
public:
/*
** 函数2,类中的函数
** 注意这是个静态函数
*/
static void fun2( int a, int b );
};
void CCall::fun2( int a, int b )
{
cout << "fun2 is called" << endl;
cout << a << " " << b << endl;
cout << "*****************" << endl;
return;
}
//////////////////////////////////////////////////////////////////////////
void main(void)
{
CBase bbbbb;
bbbbb.RegisterCallback( fun1, 1, 2 );
bbbbb.CallCallback();
bbbbb.RegisterCallback( CCall::fun2, 10, 20 );
bbbbb.CallCallback();
}
- .NET 回调函数
- 回调函数
- 回调函数
- 回调函数概念
- 回调函数
- 回调函数
- 回调函数
- 回调函数 相关
- delphi 回调函数
- 回调函数
- 回调函数
- 回调函数学习
- 回调函数
- 关于回调函数
- 透析回调函数
- 回调函数
- 什么是回调函数
- 回调函数
- 如何使用vim文本编辑器(深入学习)
- 借我一生
- Hash 算法及其应用
- 开源ETL工具kettle系列之常见问题
- OSGi 插件管理
- 回调函数
- Seven habits of effective text editing
- Android EditView属性
- 对铁道部12306火车票购票网站的浅析
- 查看新浪博客的技术文章
- codeforces 223B Two strings
- uCOS3于s3c2440的移植
- 让ubuntu支持新浪微博
- C++运算符重载