-
Notifications
You must be signed in to change notification settings - Fork 1
/
Session11E.cpp
68 lines (47 loc) · 840 Bytes
/
Session11E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include<string>
using namespace std;
class Point{
int x, y;
public:
/*Point(){
x = 0;
y = 0;
}*/
// Initialization List
Point():x(0), y(0){
}
/*Point(int a, int b){
x = a;
y = b;
}*/
Point(int a, int b):x(a), y(b){
}
void showPoint(){
cout<<"Point is: "<<x<<" : "<<y<<endl;
}
// Passing Object as Reference
Point operator+(Point &p){
Point obj;
obj.x = x + p.x;
obj.y = y + p.y;
return obj;
}
};
/*Point operator+(int a){
}*/
int main(){
int x = 10;
int &y = x; // Reference Copy
Point p1(10, 20);
Point p2(30, 40);
Point p3;
p1.showPoint();
p2.showPoint();
//p3 = p1.operator+(p2);
p3 = p1 + p2; //p1 + p2 -> p1.operator+(p2);
p3.showPoint();
//p3 = p1 + 10; // -> p3 = p1.operator+(10);
//p3 = 10 + p2; // -> p3 = 10.operator+(p2)
return 0;
}