Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

g++ - When did "and" become an operator in C++

I have some code that looks like:

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

This causes an error in g++ like so:

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

so after cursing the fool that defined "and" as &&, I added

#ifdef and
#undef and
#endif

and now I get

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

Which leads to my question of WHEN did "and" become an operator in C++? I can't find anything that indicates it is, except of course this message from g++

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From the C++03 standard, section 2.5:

2.5 Alternative tokens

Alternative token representations are provided for some operators and punctuators. In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling. The set of alternative tokens is defined in Table 2.

Table 2—alternative tokens

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...