fork download
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. struct big_int
  5. {
  6. T value;
  7. operator T() { return value; }
  8.  
  9. big_int& operator+=(big_int const& other)
  10. {
  11. value += other.value;
  12. return *this;
  13. }
  14.  
  15. template <typename U>
  16. big_int& operator+=(U const& v)
  17. {
  18. value += v;
  19. return *this;
  20. }
  21.  
  22. big_int& operator++()
  23. {
  24. ++value;
  25. return *this;
  26. }
  27.  
  28. big_int operator++(int)
  29. {
  30. big_int temp = *this;
  31. ++value;
  32. return temp;
  33. }
  34. };
  35.  
  36. template <typename T>
  37. struct small_int
  38. {
  39. T value;
  40. operator T() { return value; }
  41. };
  42.  
  43. typedef big_int<long> bigInt;
  44. typedef small_int<char> smallInt;
  45.  
  46. class Problematic
  47. {
  48. public:
  49. Problematic(bigInt) {}
  50. Problematic(smallInt) {}
  51. };
  52.  
  53. int main()
  54. {
  55. bigInt bi = { 4 };
  56. std::cout << bi << "\n";
  57.  
  58. bi+=7;
  59. std::cout << bi << "\n";
  60.  
  61. long l = 4;
  62. bi+=l;
  63. std::cout << bi << "\n";
  64.  
  65. ++bi;
  66. std::cout << bi << "\n";
  67.  
  68. bi++;
  69. std::cout << bi << "\n";
  70.  
  71. std::cout << (bi == l) << "\n";
  72. std::cout << (bi == 17) << "\n";
  73. }
  74.  
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
4
11
15
16
17
0
1