Just got the book C++ Programming in easy steps. I just did the following program and although I ran it with now problems the book and this program really do not at all help understand how an enum or a typedef are usefull in the real world.

#include <iostream>
using namespace std;

int main()
{
    const double PI = 3.1315926536;
    cout<< "6\" circle circumference: " << (PI * 6) << endl;

    enum
    {RED=1, YELLOW, GREEN, BROWN, BLUE, PINK, BLACK };
    cout<< "I shot a red worth: " << RED << endl;
    cout<< "Then a blue worth: " << BLUE << endl;
    cout<< "Total scored: " << ( RED + BLUE ) << endl;

    typedef enum {NEGATIVE, POSITIVE} charge;
    charge neutral = NEGATIVE, live = POSITIVE;
    cout<< "Neutral wire: " << neutral << endl;
    cout<< "Live wire: " << live << endl;

    return 0;
}

Usually when an ENUM structure is used its something like:

enum months{"january" "febuary", etc... } the_month;

"january" in this example, like in any other place in a program, is recognized as a constant char pointer or const char*. I don't see where YELLOW or BLUE are defined. When you create a data structure you have to populate it with existing data types. typedef is useful because without it, if you wanted to use enum months with it would have to be declared as

void get_the_date(enum months month, etc...)

whereas with a typedef you declare typedef enum months{"jan"...} the function can simply be void get_the_date(months month, etc...).

Honestly I've never used enum I've never seen a use for it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.