Inference Rule:
int main() { enum day {Mon, Tue, Wed, Thu, Fri}; enum fruit {Apple, Orange, Grape, Pear }; day today = Tue; fruit dessert = Pear; // Need casting to convert between enumerand and integer today = (day) ((int) today + 1); cout << today << endl; return 0; }
public class Demo { enum day {Mon, Tue, Wed, Thu, Fri}; enum fruit {Apple, Orange, Grape, Pear }; public static void main( String args[] ) { day today = day.Tue; fruit dessert = fruit.Pear; // Need ordinal() and values() to convert back and forth // between enumerand and integer today = day.values()[today.ordinal() + 1]; System.out.println( today ); } };