Here is a small code in which the conflict occurs. is there any way to get around this correctly?
#define DEBUG 0
enum class TypeEnum : int
{
DEBUG = 0,
INFO = 1
};
It's the nature of the preprocessor. Lines beginning with # are commands to the preprocessor. #define is a command that defines a text replacement, which will rewrite your code when preprocessed. In this case, all instances of DEBUG will be replaced with 0, so the code becomes:
enum class TypeEnum : int
{
0 = 0,
INFO = 1
};
Which, of course, doesn't make sense.
min, max cough cough) and that can wrecks havoc on code, but that is an exception. Even in those cases, it doesn't hurt to avoid ALL_CAPS for C++ names.
NDEBUGthat you can use when compiling (meaning, if defined, it's a release build, otherwise it's a debug build). It's checked by standard functions likeassertand you can use it in your own code too instead of#define DEBUG 0.enum class TypeNameadd this:#undef DEBUG