April 15, 2014 Multi-Type Enumerations | ||||
---|---|---|---|---|
| ||||
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 ;) |
April 16, 2014 Re: Multi-Type Enumerations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Tue, 15 Apr 2014 17:00:36 -0400, Nordlöw <per.nordlow@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 |
Copyright © 1999-2021 by the D Language Foundation