Take the code construct that I recently found somewhere in a project:
namespace Test { enum EName { CoolEnum, NiceEnum }; enum CoolEnum { CoolVal1, CoolVal2 }; enum NiceEnum { NiceVal1, NiceVal2 }; }
My question is why the compiler allows something like this. Take an example code here:
Test::CoolEnum cEnum = Test::NiceVal1; // INVALID, as compiler refers to Test::CoolEnum value of Test::Ename enum
Why is such confusion allowed? I understand why I need to add the enum keyword, so the compiler clearly knows that I am declaring a variable of a given enumeration, and not using the value of another enumeration in the same namespace. I just donβt understand why, in the first place, such a design can be made.
source share