Expected unqualified identifier before "xor" token
xor
is an alternative token for ^
in C ++, you cannot use it as an identifier. Same for or
/ bitor
and and
/ bitand
( ||
, |
, &&
, and &
, respectively), and several others. They are essentially keywords like if
or for
.
Choose a different name for your function.
Complete list of alternative tokens (C ++ standard ยง2.12 Keywords, see section 6.2 Alternative tokens for collations):
- and
- and_eq
- bitand
- bitor
- set
- not
- not_eq
- or
- or_eq
- exclusive
- xor_eq
source to share
Moan. Yes, it is this one who chases your tail and then realizes "What?" and shake your heads.
Similarly in my case, I have a class definition that defines a class method:
List* xor(List* list)
And I get the error g ++: error: expected unqualified id before '^ token
Eventually, it turns out that xor is a synonym for ^ and as such cannot be a function name.
What's worse (in my case) is that this works great FINE on MS Windows in Visual Studio (in my case in 2010). And this is the code that has been developed with various versions of Visual Studio since 1999 (Visual Studio 6).
So now I need to rename the function and rebuild on Windows as well as g ++ on linux ... one of these issues gets bigger as you work on it.
source to share