#include <iostream>
using namespace std;
class Command
{
public:
virtual ~Command(){}
virtual void Execute(){}
protected:
Command(){}
};
template<class Owner>
class SimpleCommand: public Command
{
public:
typedef int (Owner::* Func)();
SimpleCommand(Owner* _owner, Func _fun):m_cmdOwner(_owner), m_cmdFunc(_fun){}
virtual void Execute()
{
cout<<(m_cmdOwner->*m_cmdFunc)()<<endl;
}
private:
Func m_cmdFunc;
Owner* m_cmdOwner;
};
class add
{
public:
add(int _a, int _b):m_a(_a),m_b(_b){NULL;}
int operator()(){ return m_a + m_b; }
private:
int m_a, m_b;
};
void main()
{
add sum(1,3);
SimpleCommand<add> aCommand(&sum,&add::operator());
aCommand.Execute();
system("pause");
}