type
status
date
slug
summary
tags
category
icon
password
Scoped & Un-scoped Enum
In general, when you declare a name within a set of curly braces, it limits the visibility of that name to that scope. However, this rule doesn't apply to C++98-style enum types.
In C++98-style enums, the scope of the enum values is the same as the enum type itself. Therefore, you cannot declare any name with the same identifier within the same scope.
C++11-style enum classes address this issue:
Strongly Typed Enumerators
C++98-style enum values can be implicitly converted to integer types, whereas enum class values cannot.
Forward Declaration
Enum class supports forward declaration because its underlying type defaults to
int
. vfc For C++98-style enums, you must explicitly declare their underlying type before using forward declaration.- 作者:Zack Yang
- 链接:https://zackyang.blog/article/cpp-enum-vs-enum-class
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章