1// friend functions
2#include <iostream>
3using namespace std;
4
5class 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
14Rectangle 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
22int main () {
23 Rectangle foo;
24 Rectangle bar (2,3);
25 foo = duplicate (bar);
26 cout << foo.area() << '\n';
27 return 0;
28}
1class className{
2 // Other Declarations
3 friend returnType functionName(arg list);
4};
5