enum types

Hi, huge beginner question here, what exactly is the "y2k" bit at the end used for? This was taken from another page on this website.


enum months_t { january=1, february, march, april,
may, june, july, august,
september, october, november, december} y2k;
It's just another way to say months_t. Without the y2k portion, you use the enum like this:
months_t myMonth = january;

but with the y2k bit, you can do the same thing like this:
y2k myMonth = january;


Edit: y2k replaces the need for months_t myMonth:
y2k = january;
Last edited on
The y2k at the end is just creating an instance of that enum to work with. You can either assign values of the enum to it or print it out to the screen to get the value. (A similar thing can be done at the end of structs).

1
2
3
4
5
6
7
8
9
10
11
 
enum months_t { january=1, february, march, april,
may, june, july, august,
september, october, november, december};

int main()
{
      months_t y2k;
      y2k = january;
      cout << y2k << endl;  // prints out 1
}


1
2
3
4
5
6
7
8
9
10
 
enum months_t { january=1, february, march, april,
may, june, july, august,
september, october, november, december}y2k;

int main()
{
      y2k = january;
      cout << y2k << endl;  // prints out 1
}


These 2 examples are basically the same (as far as I know), apart from in the 2nd example y2k is global.
James answer is right, I was wrong.
Thanks for the quick help.
Topic archived. No new replies allowed.