我有一些看起来像这样的代码:
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/