Enum vs Strongly typed enum

后端 未结 5 1808
长情又很酷
长情又很酷 2020-11-29 18:44

I am a beginner in C++ programming.

Today I come across a new topic: strongly typed enum. I\'ve researched it a bit but till now I am unable to find ou

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 19:12

    Enum Scope

    Enumerations export their enumerators to the surrounding scope. This has two drawbacks. First, it can lead to name clashes, if two enumerators in different enums declared in the same scope have the same name; second, it's not possible to use an enumerator with a fully qualified name, including the enum name.

    enum ESet {a0, a, a1, b1, c3};
    enum EAlpha{a, b, c}
    
    select = ESet::a; // error
    select = a;       // is ambigious
    

提交回复
热议问题