C++回调函数示例
2006-04-06 12:19
295 查看
模板 + Boost::Function。示例代码:
#include <string>
#include <iostream>
#include <boost/function.hpp>
using namespace std;
using namespace boost;
class Test
{
public:
Test(){};
virtual ~Test(){};
void Handle(string& s, unsigned int lines)
{
for(int i=0; i< lines; i++)
{
cout << s << endl;
}
};
};
template <class T>
static void CallBack(T& t, boost::function<void (T*, string&, unsigned int)> f)
{
string s("test");
f(&t, s, 3);
};
int main()
{
Test test;
CallBack<Test>(test, &Test::Handle);
return 0;
}
#include <string>
#include <iostream>
#include <boost/function.hpp>
using namespace std;
using namespace boost;
class Test
{
public:
Test(){};
virtual ~Test(){};
void Handle(string& s, unsigned int lines)
{
for(int i=0; i< lines; i++)
{
cout << s << endl;
}
};
};
template <class T>
static void CallBack(T& t, boost::function<void (T*, string&, unsigned int)> f)
{
string s("test");
f(&t, s, 3);
};
int main()
{
Test test;
CallBack<Test>(test, &Test::Handle);
return 0;
}
相关文章推荐
- C++中回调函数的简单示例
- 转载:C++回调函数示例
- C++简单的回调函数示例
- Visual C++ DLL的隐式链接示例
- C++多线程示例
- c#调用c++dll接口及回调函数
- C/C++之回调函数
- C++中类成员函数作为回调函数
- c/c++ 回调函数
- C++与Python的结合示例
- 回调函数示例
- C++之STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- 【cocos2d-x从c++到js】回调函数1——按键回调
- linux下C++动态链接C++库示例详解
- C++ map示例
- C++回调函数误区
- C++常用字符串处理函数及使用示例
- C++中const用于函数重载的示例代码
- C/C++ OpenCV五种滤波器综合示例
- C++语法概括及其示例(示例代码下载)