-
enum
Hey, I'm new to C++ but proficient in C...I came across enum in my book...It seems to me to fit the struct format which I used in C programming...Is it just used as a easily readable way to define variables? I have find you can use const to do the exact same thing? Can someone provide some clarification. Thanks
-
I just learned the basics of that a few days ago.
So.
Code:
enum Months { JAN = 1, FEB, MAR, APRIL, MAY, JUNE, JULY, AUG, SEPT, OCT, NOV, DEC, }
Usually the values of the integer constants start at 0 unless you do other wise like my example.
So if you do as i have did above it will increment each variable by 1 each time.
The Months is called a user defined type.
It's basically a set of user integer constants represented by an identifier.
You can have the same variable names as long as you have a different user defined type as far as i know.
I'm new so it's ll i know.
Cya
-
>I'm new to C++ but proficient in C...
C supports enum as well. It has for well over 20 years.
>Is it just used as a easily readable way to define variables?
You'll see enum used most often as a clever man's #define. However, they are also useful for creating integral variables with a well defined/restricted value set.