C++ 回调函数的简单例子(转)
2016-09-22 10:12
183 查看
原文转自 http://blog.csdn.net/wnlwcg/article/details/6930990#
1、调用端
2、被调用端
3、回调过程:调用回调接口【SetFun】,并设置回调接受函数【Test】 -----> 保存 被调用端传来的 参数 【myFun】-----> 等待.....----->
LetRun ----->myFun------>回调到Test
1、调用端
// 下面的这个_stdcall很重要的 void _stdcall Test(int n, string str) // 如果不定义全局变量,而定义在类中 则必须是 静态成员函数 { while (n-- > 0) { cout << n << " " << str << endl; } } int main(int argc, char* argv[]) { Call call; call.SetFun((MyFun)Test); // 调回调函数的接口,并传入一个函数作为参数 call.LetRun(10, "hello"); printf("Hello World!\n"); return 0; }
2、被调用端
typedef void(_stdcall *MyFun)(int n, string str); class Call { private: MyFun myFun; public: void SetFun(MyFun _myFun) { myFun = _myFun; } void LetRun(int n, string str) { myFun(n, str); } };
3、回调过程:调用回调接口【SetFun】,并设置回调接受函数【Test】 -----> 保存 被调用端传来的 参数 【myFun】-----> 等待.....----->
LetRun ----->myFun------>回调到Test
相关文章推荐
- C++ 回调函数的简单例子
- C++中回调函数的一个简单例子?
- C++ 回调函数的简单例子
- C++ 回调函数的简单例子
- 简单的c++回调函数设计方法
- 简单C++调用lua函数及C++和lua相互函数调用小例子
- 一个最简单的例子,清楚说明回调函数的作用和强大功能
- C++中提供了多种基本的数据类型。实际上,这些远不能满足我们的需求,如复数(第10章的例子大多是处理虚数的),再如分数。本任务将设计一个简单的分数类,完成对分数的几个运算。一则巩固基于对象编程的方法,
- 一个最简单的com组件的例子(C++)
- C++ libmemcached简单例子
- 简单使用scipy.weave混合使用Python和C++代码的简单例子
- 一个最简单的例子,清楚说明回调函数的作用和强大功能
- 一个利用友元函数结合C和C++的简单例子
- c++Web Service的简单例子
- c++简单例子
- 简单的c++回调函数设计方法
- 一个简单的回调函数的例子
- C++回调函数出错简单介绍
- 使用C++对文件加密的简单例子
- C++ Boost 之Python(一个简单的例子)