-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork.cpp
51 lines (44 loc) · 1.32 KB
/
work.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
#include <cstdio>
#include <chrono>
#include <thread>
#include <cstring>
const char *colors[] {
"\033[31m",
};
const char *reset = "\033[0m";
struct TimerClass {
std::chrono::steady_clock::time_point timestamp;
//Default constructor
TimerClass() {
timestamp = std::chrono::steady_clock::now();
printf("Created object TimerClass\n");
}
//Copy Destructor
TimerClass(const TimerClass& other) {
timestamp = other.timestamp;
printf("The copy constructor is called\n");
}
//Operator assignment operator
TimerClass& operator=(const TimerClass& other) {
if (this != &other) {
timestamp = other.timestamp;
printf("The copy assignment operator is called:\n");
}
return *this;
}
//Destructor
~TimerClass() {
auto end_line = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_line - timestamp).count();
printf("%s Time live object %ld milliseconds%s\n", colors[0], duration, reset);
}
};
int main() {
TimerClass timer1;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
TimerClass timer2 = timer1;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
TimerClass timer3;
timer3 = timer1;
return 0;
}