I have some code that looks like:
static const std::string and(\" AND \");
This causes an error in g++ like so:
Row.cpp:140
I don't know when it was introduced, it may well have been there from the beginning, but I believe the reason it's there is as an alternative to &&
for people with restricted character sets i.e. where they don't actually have the ampersand character.
There are many others too eg. and_eq
, or
, compl
and not
to name just a selection.
They were added because some of those characters are difficult to type on some keyboards.
There are several such alternatives defined in C++. You can probably use switches to turn these on/off.
They've been there since C++ 98. They're listed in the §2.5/2 of the standard (either the 1998 or the 2003 edition). The alternate tokens include: and
, or
, xor
, not
, bitand
, bitor
, compl
, and_eq
, or_eq
, xor_eq
, not
, not_eq
.
According to C++ Standard 2.12 there are predefined preprocessor tokens "which are used in
the syntax of the preprocessor or are converted into tokens for operators and punctuators." and
is one of them. In new C++ Standard there is new 2.12/2:
Furthermore, the alternative representations shown in Table 4 for certain operators and punctuators (2.6) are reserved and shall not be used otherwise:
and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq
You can use -fno-operator-names
to disable this. Alternatively, you can name your std::string
object something else!