我正在尝试构造一个简单的c ++宏,我什至无法开始。谷歌到目前为止还没有帮助。
#define blow (...) __VA_ARGS__
int main () {
blow();
}
产生以下错误:
g++ -fpermissive -std=gnu++11 -g3 -I/eclipse/workspace/shared /eclipse/workspace/shared/amanda.c++ -o /binaries/amanda
[g++ shared/amanda took 0.0 seconds]
1. /eclipse/workspace/shared/amanda.c++:7:20: warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro [enabled by default]
2. #define blow (...) __VA_ARGS__
3. ^
4. /eclipse/workspace/shared/amanda.c++: In function ‘int main()’:
5. /eclipse/workspace/shared/amanda.c++:7:15: error: expected primary-expression before ‘...’ token
6. #define blow (...) __VA_ARGS__
7. ^
8. /eclipse/workspace/shared/amanda.c++:9:2: note: in expansion of macro ‘blow’
9. blow();
10. ^
11. /eclipse/workspace/shared/amanda.c++:7:15: error: expected ‘)’ before ‘...’ token
12. #define blow (...) __VA_ARGS__
13. ^
14. /eclipse/workspace/shared/amanda.c++:9:2: note: in expansion of macro ‘blow’
15. blow();
16. ^
最佳答案
宏定义应在宏名称和(
之间没有空格:
#define blow(...) __VA_ARGS__
int main () {
blow();
}
使用空格,您可以定义普通的非可变宏
blow
,该宏会扩展为(...) __VA_ARGS__
,这会导致您出现错误消息。