Multi-Type Enumerations
Steven Schveighoffer
schveiguy at yahoo.com
Tue Apr 15 18:13:06 PDT 2014
On Tue, 15 Apr 2014 17:00:36 -0400, Nordlöw <per.nordlow at gmail.com> wrote:
> Could somebody, please, give me some enlightening examples of when it
> can be useful to have a enumerators with different types such as in
>
> enum {
> A = 1.2f, // A is 1.2f of type float
> B, // B is 2.2f of type float
> int C = 3, // C is 3 of type int
> D // D is 4 of type int
> }
>
> show in
>
> http://dlang.org/enum.html
>
> I guess my mind hasn't expanded beyond the C limitations in this regard
> ;)
Those are for anonymous enums. Enum is also the keyword for manifest
constants (think #define)
The above is equivalent to:
enum A = 1.2f;
enum B = 2.2f;
enum C = 3;
enum D = 4;
A named enum group I think has to have all the same type, because that
enum is actually a new type, and all the values have to be of that type.
-Steve
More information about the Digitalmars-d-learn
mailing list