c++ - 未初始化的枚举器默认值

标签 c++ c++11 language-lawyer

假设我们有以下声明

enum visibility
{
   On  = 0,
   Off = 1,
   maxVisibility
};

C++11/C++0x标准中maxVisibility枚举数2的保证值是?

最佳答案

是的,这是有保证的。

§ 7.2.2

If the first enumerator has no initializer,the value of the corresponding constant is zero. An enumerator-definition without an initializer gives the enumerator the value obtained by increasing the value of the previous enumerator by one.

关于c++ - 未初始化的枚举器默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18868599/

相关文章:

c++ - 生成位掩码

C++ 模板 : correct way to return a new type

c++ - 如何获取右值引用参数并将其传递到其他地方?

c++ - 嵌套的基于范围的 for 语句是否严格合法?

c++ - 通过未定义的无符号整数读取无符号字符数组是否不安全?

c++ - C++ STL 中排序算法的工作

c++ - <functional> 中奇怪的模板语法

c++ - 类模板中的 Typedef 评估

c++ - 用数学表达式拆分字符串

c++ - 基于范围的 'for' 循环是否会弃用许多简单的算法?