callback:C++中回调(CallBack)的使用思路
方法
疯狂代码 http://CrazyCoder.cn/ ĵ:http:/CrazyCoder.cn/VC/Article65508.html
回调是个很有用也很重要概念当发生某种事件时系统或其他将会自动你定义段回调在windows编程使用
场合很多比如Hook回调:MouseProc,GetMsgProc以及EnumWindows,DrawState回调等等还有很多系统级回
调过程 般情况下, 我们使用回调基本都是采用C语言风格. 这里介绍种C风格回调对象思路方法. 采用template实
现.
view plaincopy to clipboardpr?
template < Class, typename ReturnType, typename Parameter >
SingularCallBack
{
public:
typedef ReturnType (Class::*Method)(Parameter);
SingularCallBack(Class* __instance, Method _method)
{
//取得对象例子地址,及思路方法地址
_instance = __instance;
method = _method;
};
ReturnType operator(Parameter parameter)
{
// 对象思路方法
(_instance->*method)(parameter);
};
ReturnType execute(Parameter parameter)
{
// 对象思路方法
operator(parameter);
};
- 1
- 2
前往页