Alex Rivera | Logout

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

Asked 2010-03-10T19:16:02.123
36

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++

Edit
Report

1 Answer

12

You can use -fno-operator-names to disable this. Alternatively, you can name your std::string object something else!

answered 2010-03-10T19:28:23.017

Your Answer