[英]C++ #define value not being read in cpp file
在我的C ++ .h
文件中:
class foo {
#define useThis true
...
}
在我的.cpp
文件中:
#if useThis
... generate A code
#else
... generate B code
#endif
问题是在.cpp
文件中未读取#define
值,因此正在发生的是同时生成A和B。
我将.h
文件包含在.cpp
文件的顶部。
对于某些编译器(例如Visual Studio),不能在宏中使用布尔值(尽管可以在g ++下工作)。 交叉编译器的方式应为:
#define useThis 1
或者,定义一个没有值的宏,并使用ifdef
来测试是否已定义:
#define useThis
#ifdef useThis
...
#else
...
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.