Using enum type within a Class - C++ Class

C++ examples for Class:Class Creation

Description

Using enum type within a Class

Demo Code

#include <iostream>

using namespace std;

class Cheesecake {
public:/*from w w  w  .  ja  va2s.  c o  m*/
    enum Flavor {
        A, B, C,
        D, E, F
    };
    Flavor SelectedFlavor;
    int AmountLeft;
    void Eat() {
        AmountLeft = 0;
    }
};


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

Result


Related Tutorials