RSS Feed for This PostCurrent Article

Using Enumerations in C++

Enumerations in C++ work in a similar manner to other languages, to restrict a particular variable to having a specific set of values.

For example:

enum Names {Fred, Mary, John, Anne}

In this case, a  new type is created, which may have <b>only</b> the values Fred, Mary, John, Anne.

The compiler will represent Fred as 0, Mary as 1  and so on. John will take the next value, which here will be 2.

Trackback URL

Sorry, comments for this entry are closed at this time.