Is “enum class” a class type in C++?

前端 未结 2 872
予麋鹿
予麋鹿 2021-02-05 00:15

I read about enumeration declaration in C++ using cppreference.

Then I have made Enum class and check whether it is a class type or not using std:

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 00:55

    enum class is not a class definition - the combination of keywords is used to define a scoped enumeration, which is a completely separate entity from a class.

    std::is_class correctly returns false here. If you use std::is_enum, it will return true.


    From the Standard:

    The enumeration type declared with an enum-key of only enum is an unscoped enumeration, and its enumerators are unscoped enumerators. The enum-keys enum class and enum struct are semantically equivalent; an enumeration type declared with one of these is a scoped enumeration, and its enumerators are scoped enumerators.

    There is no mention of an enum class being a "class type" anywhere in the Standard.

提交回复
热议问题