fork(1) download
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. class X {
  5. public:
  6. X(T d): y(d) {}
  7.  
  8. private:
  9. class Y {
  10. public:
  11. Y(T d): data(d) {}
  12.  
  13. private:
  14. T data;
  15.  
  16. friend std::ostream &operator <<(std::ostream &os, Y const& y)
  17. {
  18. os << "Y(" << y.data << ")";
  19. return os;
  20. }
  21. };
  22.  
  23. Y y;
  24.  
  25. template <typename U>
  26. friend std::ostream &operator <<(std::ostream &os, const X<U> &x);
  27. };
  28.  
  29. template <typename U>
  30. std::ostream &operator <<(std::ostream &os, const X<U> &x) {
  31. os << "X " << x.y;
  32. return os;
  33. }
  34.  
  35. int main() {
  36. std::cout << X<int>(1);
  37. return 0;
  38. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
X Y(1)