How to Extend existing enums

Picked up this very interesting example on extending enum's. The program is self explanatory and is as follows:



//Program tested on Microsoft Visual Studio 2008 - Zahid Ghadialy
#include<iostream>

using namespace
std;

int
main()
{

enum
Enum1
{

value1,
value2,
value3,
final_value = value3
};


//Print out the enum values
cout<<"Enum1 values : ";
for
(int i = 0; i <= final_value; i++)
cout<<Enum1(i)<<" ";
cout<<endl;

enum
extendedEnum1
{

value4 = final_value + 1,
value5,
value6,
new_final_value = value6
};


//Print out the enum values
cout<<"extendedEnum1 values : ";
for
(int i = 0; i <= new_final_value; i++)
cout<<extendedEnum1(i)<<" ";
cout<<endl;

return
0;
}



The output is as follows:


Check out this stream