使用先前定义的成员作为枚举定义中后来成员的一部分是合法的吗?

Geo*_*off 6 c++ enums portability

namespace ValueType {
  enum Enum {
    Boolean = 0,
    Float = 1,
    Double,
    SInt = 8,
    SLong,
    UInt = SInt + (1 <<4),
    ULong = SLong + (1 << 4)
  };
}
Run Code Online (Sandbox Code Playgroud)

Jer*_*fin 12

是的 - 要求是它是一个完整的常量表达式.C++标准包括以下示例:

enum { d, e, f=e+2 };
Run Code Online (Sandbox Code Playgroud)