读书人

这么算回调吗

发布时间: 2013-07-01 12:33:04 作者: rapoo

这样算回调吗?

                                                                            
[解决办法]
搜索 Command模式
[解决办法]
引用:
Quote: 引用:

搜索 Command模式

可还不是回调啊
我想知道类的回调的方式 是怎么写的?
dll中怎么定义 主程序里怎么定义
谁发起调用?
#include <iostream>
using namespace std;
class Command{
public:
virtual void Execute() = 0;
};

template <class T>
class SimpleCommand : public Command{
public:
typedef void (T::*Action)();
SimpleCommand(T *tc, Action action);
void Execute();

private:
Action _action;
T *_tc;
};

template <class T>
SimpleCommand <T>::SimpleCommand(T *tc, Action action):
_tc(tc), _action(action){
};

template <class T>
void SimpleCommand <T>::Execute(){
(_tc->*_action)();
};

class CallBackClass{
public:
CallBackClass(){};
void action(){
cout<<"This is a Call back action!"<<endl;


};
};

void main()
{

CallBackClass* mycall = new CallBackClass();
Command *command = new SimpleCommand<CallBackClass>(mycall, &CallBackClass::action);
command->Execute();
}

读书人网 >C++

热点推荐