这样算回调吗?
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();}
搜索 Command模式
#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();}
};};void main(){CallBackClass* mycall = new CallBackClass();Command *command = new SimpleCommand<CallBackClass>(mycall, &CallBackClass::action);command->Execute();}