📄 main.cpp
字号:
#include <iostream>
#include <stdlib.h>
#include "command.h"
using namespace std;
// These are my commands
class MyCommands {
public:
void MenuNew() { cout << "New!" << endl; }
void MenuOpen() { cout << "Open!" << endl; }
void MenuClose() { cout << "Close!" << endl; }
void MenuQuit() { cout << "Quit!" << endl; }
};
// These are more commands
class MoreCommands {
public:
void CrashComputer() { cout << "Oops!" << endl; }
void ForgetEverything() { cout << "I forgot!" << endl; }
};
// These are the handlers that call my commands
Command *NewCommand;
void NewMenuHandler() {
NewCommand->Execute();
}
Command *OpenCommand;
void OpenMenuHandler() {
OpenCommand->Execute();
}
int main(int argc, char *argv[])
{
MyCommands *commands = new MyCommands();
NewCommand =
new SpecificCommand<MyCommands>
(commands, &MyCommands::MenuNew);
OpenCommand =
new SpecificCommand<MyCommands>
(commands, &MyCommands::MenuOpen);
// Test out the menu items by
// calling the handlers directly.
NewMenuHandler();
OpenMenuHandler();
// Now change my mind. I want the handlers
// to work with a different class.
delete NewCommand;
delete OpenCommand;
MoreCommands *morecommands = new MoreCommands();
NewCommand =
new SpecificCommand<MoreCommands>
(morecommands, &MoreCommands::CrashComputer);
OpenCommand =
new SpecificCommand<MoreCommands>
(morecommands, &MoreCommands::ForgetEverything);
// Test out the menu items by
// calling the handlers directly.
NewMenuHandler();
OpenMenuHandler();
system("PAUSE");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -