enum(enumeration) is a user-defined type consisting of a set of enumerators( enumerator --- named integer constant)

Simple enum definition:

 
 
enum Color
{
 
    COLOR_BLACK,
    COLOR_RED,
    COLOR_BLUE,
    COLOR_GREEN,
    COLOR_WHITE,
    COLOR_CYAN,
    COLOR_YELLOW,
    COLOR_MAGENTA
};
 
 
Color eColor = COLOR_WHITE;
 

Why we need enum?

Sometimes you want constraint the value of a variable, for example when you want to represent sex, you want the value only can be male and female. you can use enum. When ever you try to assign other value to the variable, compiler will report error.

You can think enum value as const int variable and the enum variable can only hold the range of these const variables.

Use enum in parameter

 
void foo( Color col ) ;
 

Use enum in switch statement

 
void foo( Color col ) {
    switch( col ) {
        case COLOR_BLACK:
        //
        break;
    }
}
 

If the enum defined in class declaration, use scope operator to reference enum value. ClassName::COLOR_BLACK for example.