gpt4 book ai didi

c++ - 枚举成员的值,当某些成员具有用户定义的值时

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:05:42 27 4
gpt4 key购买 nike

enum ABC{
A,
B,
C=5,
D,
E
};

D和E能保证大于5吗?
A 和 B 是否保证小于 5(如果可能)?

编辑:如果我说 C=1

会发生什么

最佳答案

它由 C++ 标准 7.2/1 保证:

The identifiers in an enumerator-list are declared as constants, and can appear wherever constants are required. An enumerator-definition with = gives the associated enumerator the value indicated by the constant-expression. The constant-expression shall be of integral or enumeration type. 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/2781015/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com