fork(1) download
  1. #include <iostream>
  2.  
  3. struct D{
  4. int x;
  5. D(int a):x(a){}
  6. };
  7.  
  8. struct C{
  9. D d;
  10. C(int x=0):d(x){}
  11. friend C operator+(C a,C b){
  12. return C{a.d.x+b.d.x};
  13. }
  14. friend std::ostream& operator<< (std::ostream &os, const C &x){
  15. return os<<" C["<<x.d.x<<"]";
  16. }
  17.  
  18. };
  19.  
  20. int main()
  21. {
  22.  
  23. C c;
  24. c = 1 + c;
  25. std::cout << c;
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5028KB
stdin
Standard input is empty
stdout
 C[1]