fork download
  1. // friend functions
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Rectangle {
  6. int width, height;
  7. public:
  8. Rectangle() {}
  9. Rectangle (int x, int y) : width(x), height(y) {}
  10. int area() {return width * height;}
  11. friend Rectangle duplicate (const Rectangle&);
  12. };
  13.  
  14. Rectangle duplicate (const Rectangle& param)
  15. {
  16. Rectangle res;
  17. res.width = param.width*2;
  18. res.height = param.height*2;
  19. return res;
  20. }
  21.  
  22. int main () {
  23. Rectangle foo;
  24. Rectangle bar (2,3);
  25. foo = duplicate (bar);
  26. cout << foo.area() << '\n';
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
24