fork download
  1. #include <stdio.h>
  2.  
  3. enum class Foo {
  4. VAL_A = 0, VAL_B = 1, VAL_C = 2
  5. };
  6.  
  7. enum class Bar {
  8. VAL_A = 10, VAL_B = 11, VAL_C = 12
  9. };
  10.  
  11. template<typename T>
  12. void TestSwitch(T op)
  13. {
  14. printf("%d: ", static_cast<int>(op));
  15. switch (op) {
  16. case T::VAL_A: printf("aaa\n"); break;
  17. case T::VAL_B: printf("bbb\n"); break;
  18. case T::VAL_C: printf("ccc\n"); break;
  19. default: break;
  20. }
  21. }
  22.  
  23. int main() {
  24. TestSwitch(Foo::VAL_A);
  25. TestSwitch(Bar::VAL_C);
  26. }
  27.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
0: aaa
12: ccc