|
比较懒,又不想代码失去基本的优雅,于是写了这么一个玩意儿。
- #define MESSAGE_FUNCTION_BEGIN(x) switch(x) {
- #define MESSAGE_FUNCTION(x,y) case x: { y(x); break; }
- #define MESSAGE_FUNCTION_END }
- void Do_1(int x)
- {
- printf("[Do_1]x=%d.\n", x);
- }
- void Do_2(int x)
- {
- printf("[Do_2]x=%d.\n", x);
- }
- void Do_3(int x)
- {
- printf("[Do_3]x=%d.\n", x);
- }
- void RegFunction(int x)
- {
- MESSAGE_FUNCTION_BEGIN(x);
- MESSAGE_FUNCTION(1, Do_1);
- MESSAGE_FUNCTION(2, Do_2);
- MESSAGE_FUNCTION(3, Do_3);
- MESSAGE_FUNCTION_END;
- }
复制代码 嘿嘿,测试一下。- RegFunction(1);
- RegFunction(2);
- RegFunction(3);
复制代码 输出
[Do_1]x=1.
[Do_2]x=2.
[Do_3]x=3.
OK,懒惰成功!
|
|