Is the use of previously defined members as part of later members in an enum definition legal?

c++, enums, portability

Solution

Yes -- the requirement is that it's an integral constant expression. The C++ standard includes the following example:

enum { d, e, f=e+2 };

Problem

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

Original source