在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#include <iostream> using namespace std; class action { public: action(){} ~action(){} void forward(){cout<<"forward"<<endl;} void backward(){cout<<"backward"<<endl;} }; class command { public: command(){} virtual ~command(){} virtual void execute()=0; virtual void unexecute()=0; }; class buttoncommand : public command { public: buttoncommand(){} virtual ~buttoncommand(){} void execute(){act->forward();} void unexecute(){act->backward();} private: action *act; }; class Switch { public: Switch():cmd(new buttoncommand){} ~Switch(){} void open(){cmd->execute();} void close(){cmd->unexecute();} private: command *cmd; }; int main() { Switch *sw=new Switch; sw->open(); sw->close(); delete sw; system("pause"); return 0; } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论