1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include #define COMMAND(NAME) { #NAME, NAME # # _command } using namespace std; struct command { char * name; void( * function)(int r_nArg); }; void quit_command(int r_nArg) { cout << "quit_command " << r_nArg; } void help_command(int r_nArg) { cout << "help_command " << r_nArg; } struct command commands1[] = { { "help", help_command }, { "quit", quit_command }, }; struct command commands2[] = { COMMAND(help), COMMAND(quit), }; int _tmain(int argc, _TCHAR * argv[]) { commands1[0].function(3000); cout << endl; commands1[1].function(5000); return 0; } |