enum field : Class Member « Class « C++






enum field

  
#include <iostream>
using namespace std;
enum Days { Monday, Tuesday, Wednesday, Thursday, Friday };

class MyClass 
{
  public:
    int *lucky_number;
    enum Days lucky_day;
};


int main(void)
{
   MyClass wow;
   int lucky = 1500;

   wow.lucky_day = Monday; 
   
   wow.lucky_number = &lucky;

   cout << *(wow.lucky_number) << endl;
   switch (wow.lucky_day) 
   {
     case Monday: cout << "Monday\n";
                  break;

     default: cout << "My lucky day ain't any day but Monday\n";   
   };
}
  
    
  








Related examples in the same category

1.The Member Initialization SyntaxThe Member Initialization Syntax
2.Assign values using the member initialization syntaxAssign values using the member initialization syntax
3.Use class name to reference field name
4.getName member function reads from the name member variable and the setName member function writes to it