-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSession14.cpp
More file actions
55 lines (40 loc) · 909 Bytes
/
Session14.cpp
File metadata and controls
55 lines (40 loc) · 909 Bytes
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
#include<iostream>
#include<string>
using namespace std;
// Basic Copy Operation
class Order{
int oid;
string customerName;
int price;
public:
Order(){
oid = 0;
customerName = "NA";
price = 0;
}
void setDataForOrder(int oid, string customerName, int price){
this->oid = oid;
this->customerName = customerName;
this->price = price;
}
void showDataForOrder(){
cout<<"==="<<oid<<"===\n";
cout<<"Customer:\t"<<customerName<<"\n";
cout<<"Price:\t"<<price<<"\n";
}
};
int main(){
// Copying Object
// Copy of Object is happening automatically for us !!
Order o1;
o1.setDataForOrder(101,"John",3000);
Order o2 = o1; // Copy Object
Order o3(o1); // Copy Object
o1.showDataForOrder();
o2.showDataForOrder();
o3.showDataForOrder();
cout<<"Address of o1 is: "<<&o1<<"\n";
cout<<"Address of o2 is: "<<&o2<<"\n";
cout<<"Address of o3 is: "<<&o3<<"\n";
return 0;
}