fork(10) download
  1.  
  2. /// Test enum
  3. enum class Fruit
  4. {
  5. apple,
  6. banana,
  7. orange,
  8. pineapple,
  9. lemon
  10. };
  11.  
  12. /// Non-scalable way
  13. Fruit& operator++(Fruit& f)
  14. {
  15. switch(f)
  16. {
  17. case Fruit::apple: return f = Fruit::banana;
  18. case Fruit::banana: return f = Fruit::orange;
  19. case Fruit::orange: return f = Fruit::pineapple;
  20. case Fruit::pineapple: return f = Fruit::lemon;
  21. case Fruit::lemon: return f = Fruit::apple;
  22. }
  23. }
  24.  
  25.  
  26. #include <iostream>
  27. std::ostream& operator<<(std::ostream& os, Fruit f)
  28. {
  29. switch(f)
  30. {
  31. case Fruit::apple: os << "Fruit::apple"; return os;
  32. case Fruit::banana: os << "Fruit::banana"; return os;
  33. case Fruit::orange: os << "Fruit::orange"; return os;
  34. case Fruit::pineapple: os << "Fruit::pineapple"; return os;
  35. case Fruit::lemon: os << "Fruit::lemon"; return os;
  36. }
  37. }
  38. int main()
  39. {
  40. Fruit f = Fruit::banana;
  41. std::cout << "f = " << f << ";\n";
  42. std::cout << "++f = " << ++f << ";\n";
  43. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
f = Fruit::banana;
++f = Fruit::orange;