www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Multi-Type Enumerations

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
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 ;)
Apr 15 2014
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 15 Apr 2014 17:00:36 -0400, Nordl=C3=B6w <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 =3D 1.2f,  // A is 1.2f of type float
    B,         // B is 2.2f of type float
    int C =3D 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 regar=
d =
 ;)
Those are for anonymous enums. Enum is also the keyword for manifest = constants (think #define) The above is equivalent to: enum A =3D 1.2f; enum B =3D 2.2f; enum C =3D 3; enum D =3D 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
Apr 15 2014