c++ - "and"什么时候成为 C++ 中的运算符

标签 c++ g++

我有一些看起来像这样的代码:

static const std::string and(" AND ");

这会导致 g++ 中的错误,如下所示:

Row.cpp:140: error: expected unqualified-id before '&&' token

所以在诅咒了将“and”定义为&&的傻瓜之后,我添加了

#ifdef and
#undef and
#endif

现在我明白了

Row.cpp:9:8: error: "and" cannot be used as a macro name as it is an operator in C++

这导致我的问题是“和”何时成为 C++ 中的运算符?我找不到任何表明它的东西,当然除了来自 g++ 的这条消息

最佳答案

来自 C++03 标准,第 2.5 节:

2.5 替代代币

为某些运算符和标点符号提供了替代标记表示。在语言的所有方面,除了拼写之外,每个替代标记的行为分别与其主要标记相同。替代标记集在表 2 中定义。

表 2 - 替代标记

alternative primary 
  <%         { 
  %>         } 
  <:         [ 
  :>         ] 
  %:         # 
  %:%:       ## 
  and        && 
  bitor      | 
  or         || 
  xor        ˆ 
  compl      ˜ 
  bitand     & 
  and_eq     &= 
  or_eq      |= 
  xor_eq     ˆ= 
  not        ! 
  not_eq     != 

关于c++ - "and"什么时候成为 C++ 中的运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2419805/

相关文章:

c++ - __attribute__ ((__packed__)) 对嵌套结构的影响是什么?

c++ - 我的初始化列表中的小错字导致无法形容的痛苦

c++ - std::shared_ptr 内部结构,弱计数超过预期

c++ - 通过迭代器更改对象成员?

c++ - 如何将 glRotatef() 转换为 glMultMatrixd() 的乘法矩阵

c++ - 将 C 程序转换为 C++

c++ - Distcc 与 C++ undefined reference

c++ - 配置 : error: C++ compiler cannot create executables

gcc - 在 Angström (Beagleboard) 上编译 Hello World

c++ - SFINAE 和衰变不能同时发挥作用。为什么?