1

I really want to be able to do this in my code, but this error: redefinition of enumerator 'TEST'

enum test1 {
    TEST
};

enum test2 {
    TEST
};

Is there a way to get around this since I really want the same names inside the different enums. Also why is this happening?

jujumumu
  • 350
  • 4
  • 12

1 Answers1

8

This can be solved by defining your enums as enum class instead of plain enums. By defining as a plain enum, the names are unscoped and therefore conflict with each other. If they are defined as enum classes, the names are contained within the scope of the enum. Note, however, that as a result of this change, you will also need to use the scope resolution operator, e.g. test1::TEST and test2::TEST.