我有一些看起来像的代码:
static const std::string and(" AND ");
Run Code Online (Sandbox Code Playgroud)
这会导致g ++中的错误,如下所示:
Row.cpp:140: error: expected unqualified-id before '&&' token
Run Code Online (Sandbox Code Playgroud)
所以在诅咒将"和"定义为&&的傻瓜后,我补充道
#ifdef and
#undef and
#endif
Run Code Online (Sandbox Code Playgroud)
现在我明白了
Row.cpp:9:8: error: "and" cannot be used as a macro name as it is an operator in C++
Run Code Online (Sandbox Code Playgroud)
这导致我的问题是什么"和"成为C++中的运算符?我找不到任何表明它的东西,当然除了来自g ++的这条消息
int*_*jay 25
从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 !=
Run Code Online (Sandbox Code Playgroud)
Jer*_*fin 14
他们自C++ 98以来一直在那里.他们被列入标准的§2.5/ 2(1998年或2003年版).备选令牌包括:and
,or
,xor
,not
,bitand
,bitor
,compl
,and_eq
,or_eq
,xor_eq
,not
,not_eq
.
根据C++标准2.12,有预定义的预处理器标记",它们在预处理器的语法中使用,或者被转换为运算符和标点符号的标记." and
是其中之一.在新的C++标准中有新的2.12/2:
此外,表4中针对某些运营商和标点符号(2.6)所示的替代表示是保留的,不得另行使用:
and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq
归档时间: |
|
查看次数: |
5144 次 |
最近记录: |