Enum??

Could someone explain to me what Enum is? I am having a hard time understanding it, and why it would be used. Thanks y'all :)
It's a quicker way to define a bunch of constants, especially when you don't care about their numeric values.
If there numeric value isn't important, why would it matter if its a constant? Could't you just use it as an int or double..or whatever?
I don't understand you.
Try reading http://www.cprogramming.com/tutorial/enum.html
closed account (10oTURfi)
Sometimes you use enums when you CARE about numeric values. As hamsterman said, its quickest way to define constants. This is example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Somewhere in WoW emulator code...
//Those values represent entries in database
enum
{
    SAY_AGGRO                   = -1532057,
    SAY_SUMMON1                 = -1532058,
    SAY_SUMMON2                 = -1532059,
    SAY_EVOCATE                 = -1532060,
    SAY_ENRAGE                  = -1532061,
    SAY_KILL1                   = -1532062,
    SAY_KILL2                   = -1532063,
    SAY_DEATH                   = -1532064,

    NPC_ASTRAL_FLARE            = 17096,
    SPELL_ASTRAL_FLARE_PASSIVE  = 30234,

    SPELL_HATEFUL_BOLT          = 30383,
    SPELL_EVOCATION             = 30254,
    SPELL_ENRAGE                = 30403,
    SPELL_BERSERK               = 26662
};
closed account (zb0S216C)
An instance of an enumeration list can only be assigned to the enumerators within the same list. This becomes useful for when a variable can only have certain values. Here's an example:

1
2
3
4
5
6
7
enum Direction
{
    North, East, South, West
};

Direction NewDirection( North ); // OK
NewDirection = 100;              // Error. Must be an enumerator from Direction. 


Enumerator lists have an underlying type, such as char, short, and int. The unsigned, and signed qualifiers are also used. The underlying type can be no other than the latter types. C++11 is introducing strongly-typed enums.

The enumerators are declared constant implicitly by the compiler.

Wazzak
Last edited on
Topic archived. No new replies allowed.