fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. enum one
  5. {
  6. a = 1,
  7. b,
  8. c,
  9. d,
  10. };
  11.  
  12. enum two
  13. {
  14. two_undefined,
  15. B = 1,
  16. C,
  17. D,
  18. A,
  19. };
  20.  
  21. template <int invalue>
  22. class enum_converter {
  23. public:
  24. static const two value = two_undefined;
  25. };
  26.  
  27. template <>
  28. class enum_converter<a> {
  29. public:
  30. static const two value = A;
  31. };
  32.  
  33. template <>
  34. class enum_converter<b> {
  35. public:
  36. static const two value = B;
  37. };
  38.  
  39. template <>
  40. class enum_converter<c> {
  41. public:
  42. static const two value = C;
  43. };
  44.  
  45. template <>
  46. class enum_converter<d> {
  47. public:
  48. static const two value = D;
  49. };
  50.  
  51.  
  52. int main() {
  53. one aaa = a;
  54. two AAA = enum_converter<a>::value;
  55. cout << "aaa:" << aaa << endl;
  56. cout << "AAA:" << AAA << endl;
  57. return 0;
  58. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
aaa:1
AAA:4