fork(1) download
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. class Number
  5. {
  6. T val;
  7. template<typename U>
  8. friend std::ostream& operator<< (std::ostream& os, const Number<U>& num);
  9. public:
  10. Number() : val(T{}) { }
  11. Number(T value) : val{ value } { }
  12. };
  13.  
  14. template <typename T>
  15. std::ostream& operator<< (std::ostream& os, const Number<T>& num)
  16. {
  17. os << num.val;
  18. return os;
  19. }
  20.  
  21. int main()
  22. try
  23. {
  24. Number<int> a;
  25. a = 10;
  26. std::cout << a;
  27. return 0;
  28. }
  29. catch (std::exception& e)
  30. {
  31. std::cout << e.what();
  32. return 1;
  33. }
  34. catch (...)
  35. {
  36. std::cout << "Unknown error";
  37. return 2;
  38. }
  39.  
Success #stdin #stdout 0.01s 5484KB
stdin
Standard input is empty
stdout
10