Do we really need “enum class” in C++11?

后端 未结 5 1947
北恋
北恋 2020-12-08 13:24

When we have,

struct E { enum E_ { HELLO }; }; // \'E\' is inheritable

then why do we need,

enum class E { HELLO };  // \'E         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 13:48

    Besides what was already mentioned, an advantage of enum class is better type safety - the enum class enumerators don't convert implicitly to integers.

提交回复
热议问题