c++ - 运算符 '==' 没有左操作数

标签 c++ gcc c-preprocessor

给定:

#if defined(TESTING) 
   #if (TESTING == UNIT_TEST)
            State<StateTypeEnum, EventTypeEnum>::_isIgnoredEvent = false;
            State<StateTypeEnum, EventTypeEnum>::_isInvalidEvent = false;
   #endif
#endif

TESTING 被定义,UNIT_TESTTESTING == UNIT_TEST,为什么 GCC 说

../testing/fsm/../../fsm/h/state.h:207:17: error: operator '==' has no left operand
    #if (TESTING == UNIT_TEST)
                 ^

最佳答案

看起来您只是定义了 TESTING 而没有用值定义它,无论是内联的还是作为编译器命令行的一部分。

#define TESTING

它已被定义,并且#if defined 测试为真,但比较将不起作用,因为它的宏替换值是空的(或错误的类型)。

但是,如果您给它一个值,那么您的代码就可以工作。

#define TESTING 1
#define UNIT_TEST 1

#if defined(TESTING) 
#if (TESTING == UNIT_TEST)
cout << "Unit test";
#endif
#endif

关于c++ - 运算符 '==' 没有左操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24720534/

相关文章:

c++ - 来自另一个线程的发出信号的qt链接器错误

linux - 如何定义 "wstring"?

C++宏解析问题

c - #ifdef#else - 没有选择分支

c++ - 未定义对 `typeinfo for class' 的引用

c++ - Clang 无法使用 libstdc++ 识别 std::shared_ptr

c++ - 如何强制编译器显示隐式构造函数

c++ - 为什么方法重载或枚举标志定义会触发 gcc7.2 编译器警告?

c++ - 我可以安全地使用#ifdef 来了解是否包含 c++ std header 吗?

c++ - 使用 IXMLHTTPRequest2 流式传输时如何在 Windows 8 上禁用缓存?