C++ enum type within Class

Description

C++ enum type within Class

#include <iostream>

using namespace std;

class MyClass {//from   w  w  w.  j ava 2 s  .com
public:
    enum Flavor {
        A, B, C, D, E, F
    };
    Flavor SelectedFlavor;
    int AmountLeft;
    void Eat() {
        AmountLeft = 0;
    }
};


int main()
{
    MyClass yum;
    yum.SelectedFlavor = MyClass::B;
    yum.AmountLeft = 100;
    yum.Eat();
    cout << yum.AmountLeft << endl;
    return 0;
}



PreviousNext

Related