我试图让预处理器根据已定义的名称生成一个列表。像这样
#define LIST "Start of list!"
#ifdef WITH_FOO
#define LIST LIST "Foo"
#endif
#ifdef WITH_BAR
#define LIST LIST "Bar"
#endif
#define LIST LIST "End of list!"
我从中得到一些关于 LIST 被重新定义的警告,然后在我尝试使用 LIST 的代码中它给出了一个错误:“LIST 未在此范围内声明”,除了警告,我相信它应该是。
我怎样才能让它工作?
最佳答案
你可以使用一些辅助宏:
#ifdef WITH_FOO
# define LIST_FOO "Foo"
#else
# define LIST_FOO
#endif
// ... ditto for BAR
#define FOO "Start of list!" LIST_FOO LIST_BAR "End of list!"
关于c++ - 与 C++ 预处理器连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9656266/