I have this serious problem. I have an enumeration within 2 namespaces like this:
namespace FANLib {
namespace ERROR {
enum TYPE {
/// FSL error codes
FSL_PARSER_FILE_IERROR,...
and somewhere else in my code, I use it like this:
FANLib::Log::internalLog(FSLParser::FILE_IERROR, file_ierror, true, FANLib::ERROR::FSL_PARSER_FILE_IERROR);
All compiles fine and well, but if I happen to include "windows.h", I get errors! The problem is in "WinGDI.h" which has this line:
#define ERROR 0
and makes the compiler think that, after FANLib::..., there is a zero! The error I get is :
Error 1 error C2589: 'constant' : illegal token on right side of '::'
Error 2 error C2059: syntax error : '::'
Error 3 error C2039: 'FSL_PARSER_FILE_IERROR' : is not a member of '`global namespace''
Is there anything I can do about this, without having to change my namespaces due to some thoughtless #define
? I have read in another post that I could #undef ERROR, but how safe is that?
Generally, you should avoid using all-caps identifiers as they are used for macros. In this case, I'd rename the namespace.
(As a side note, <windows.h>
#define
s other stuff like GetPrinter
and indeed it gets annoying. I usually go with #undef
then. It also helps to only include <windows.h>
in .cpp files and make sure the scope affected by the header is as small as possible.)
Renaming your namespace is the cleanest, safest, most interoperable solution.
Hopping on the "rename your namespace" bandwagon, simply because ERROR
is way too common and vague a name. Find something more descriptive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With