How to avoid name conflicts for two enum values with the same name in C++?

前端 未结 5 1128
长发绾君心
长发绾君心 2020-12-14 21:06

Enums in C++ have one major problem: You can\'t have one name in two different enums like this:

enum Browser
{
    None = 0,
    Chrome = 1,
    Firefox = 2
         


        
5条回答
  •  鱼传尺愫
    2020-12-14 21:48

    How about using scoped vs. unscoped enumeration? c++11 now offers scoped enumeration. An example would be:

    enum class Browser :  {
    
    };
    
    enum class OS :  {
    
    };
    

    Access the enumerated types via an object of the Browser or an object of OS.

提交回复
热议问题