/* For simple commands that aren’t undoable and don’t require arguments, we can use a class template to parameterize the command’s receiver. We’ll define a template subclass SimpleCommand for such commands. SimpleCommand is parameterized by the Receiver type and maintains a binding between a receiver object and an action stored as a pointer to a member function. */ template class SimpleCommand : public Command { public: typedef void (Receiver::* Action)(); SimpleCommand(Receiver* r, Action a) : _receiver(r), _action(a) {} virtual void Execute(); private: Action _action; Receiver* _receiver; }; /* The constructor stores the receiver and the action in the corresponding instance variables. Execute simply applies the action to the receiver. */ template void SimpleCommand::Execute () { (_receiver->*_action)(); }