c c++宏定义中##使用方法
#include <iostream> typedef struct command { char * name; void (*function) (void); }T_commands, *PT_commands; #define COMMAND(NAME) { #NAME, NAME##_command } void (f1_command) (void) { std::cout << "f1" << std::endl; } void (f2_command) (void) { std::cout << "f2" << std::endl; } int main() { T_commands cmds[] = { COMMAND(f1), COMMAND(f2) }; cmds[0].function(); cmds[1].function(); return 0; }