fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class weight
  6. {
  7. public:
  8. int num;
  9. weight();
  10. weight(int);
  11. weight operator+(weight);
  12. friend ostream & operator << (ostream & os,const weight &);
  13. };
  14.  
  15. ostream & operator << (ostream & os,const weight & w)
  16. {
  17. os<<w.num<<std::endl;
  18. return os;
  19. }
  20. weight::weight()
  21. {
  22.  
  23. }
  24.  
  25. weight::weight(int x)
  26. {
  27. num = x;
  28. }
  29.  
  30. weight weight::operator+(weight obj)
  31. {
  32. weight newWeight;
  33. newWeight.num = num + obj.num;
  34. return(newWeight);
  35. }
  36.  
  37.  
  38. int main( ) {
  39.  
  40. weight w1(6);
  41. weight w2(10);
  42. weight w3;
  43.  
  44. w3=w1+w2;
  45. cout << w3 << endl;
  46. }
  47.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
16