有关Enumerations的问题

来源:互联网  时间:2016/8/17 19:59:19

关于网友提出的“ 有关Enumerations的问题”问题疑问,本网通过在网上对“ 有关Enumerations的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 有关Enumerations的问题
描述:

在The C++ Programing language 中的
第4.8节中
An enumerator can be initialized by a constant-expression (§C.5) of integral type (§4.1.1). The range of an enumeration holds all the enumeration’s enumerator values rounded up to the nearest larger binary power minus 1 . The range goes down to 0 0 if the smallest enumerator is non-negative and to the nearest lesser negative binary power if the smallest enumerator is negative. This defines the smallest bit-field capable of holding the enumerator values. For example:
enum e1 { ddark, light }; / / range 0:1
enum e2 { a = 3, b = 9 }; / / range 0:15
enum e3 { min = -10, max = 1000000 }; / / range -1048576:1048575
A value of integral type may be explicitly converted to an enumeration type. The result of such a conversion is undefined unless the value is within the range of the enumeration. For example:
enum flag { x x=1 1, y y=2 2, z z=4 4, e e=8 8 }; / / range 0:15
enum flag f1  = 5; / / type error: 5 is not of type flag
enum flag f2  = flag(5) ; / / ok: flag(5) is of type flag and within the range of flag
enum flag f3  = flag g(z|e) ; / / ok: flag(12) is of type flag and within the range of flag
enum flag f4 = flag(99) ; / / undefined: 99 is not within the range of flag
The last assignment shows why there is no implicit conversion from an integer to an enumeration;
most integer values do not have a representation in a particular enumeration.
上面中的有关的range ,是什么意思啊!


解决方案1:

应该是说你的枚举范围
范围的最大值是枚举的最大值的二进制位都填满,例如上面的最大值是八,那么就是1000,那么起范围的上限是1111,即15,范围最小值是在非负时为0,负数将去最近的较小负数,和最大值取法相同

上一篇求救!!急死我了 (大送分)
下一篇VC60编译98DDK中USBVIEW例子,每个C文件末尾都有Fatal Error
明星图片
相关文章
《 有关Enumerations的问题》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)