我想知道是否可以使用预处理器 OR 或 AND 语句?我想在 _DEBUG
或 _UNIT_TEST
标签下运行此代码(?)。
我想要的是如下内容:
#if _DEBUG || _UNIT_TEST
//Code here
#endif
如果这是不可能的,是否有一种解决方法来实现相同的事情而不必使用 #elseif
复制代码?
最佳答案
#if defined _DEBUG || defined _UNIT_TEST
//Code here
#endif
您也可以使用 AND 和 NOT 运算符。例如:
#if !defined _DEBUG && defined _UNIT_TEST
//Code here
#endif
关于c++ - bool 运算符可以与预处理器一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3390603/