-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathby_move.cpp
61 lines (50 loc) · 1.18 KB
/
by_move.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
#include <iostream>
using namespace std;
class Employee {
string name;
int salary;
public:
Employee(string s, int sala) {
this->name = s;
this->salary = sala;
cout << "employee CTOR" << endl;
}
Employee(Employee &e) {
this->salary = 0;
*this = e;
cout << "employee CCTOR" << endl;
}
Employee &operator=(const Employee &e) {
if (this != &e) {
cout << "employee op =" << endl;
this->salary = e.salary;
this->name = e.name;
}
return *this;
}
Employee(Employee &&e) {
cout << "employee move CTOR" << endl;
*this = move(e);
}
Employee &operator=(const Employee &&e) {
if (this != &e) {
cout << "employee&& op =" << endl;
this->salary = e.salary;
this->name = e.name;
}
return *this;
}
~Employee(){
cout << "employee DTOR";
if(this->salary == 0){
cout << "with salary == 0";
}
cout << endl;
}
};
//int main() {
// Employee e("Yossi", 5000);
// Employee e1("Dana", 4500);
// e = (Employee&&) e1;
// return 0;
//}