-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.h
More file actions
74 lines (65 loc) · 1.32 KB
/
Copy pathclasses.h
File metadata and controls
74 lines (65 loc) · 1.32 KB
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
69
70
71
72
73
74
#include <iostream>
struct test
{
int x;
char c;
bool b;
test() : x{0}, c{'a'}, b{true} {}
test(int xx, char cc, bool bb) : x{xx}, c{cc}, b{bb} {}
~test() = default;
};
std::ostream& operator<<(std::ostream& os, const test&t)
{
return os << t.x << ' ' << t.c << ' ' << t.b;
}
struct ExceptTest
{
int* x;
char c;
bool b;
ExceptTest() : x{nullptr}, c{'a'}, b{true} {}
ExceptTest(int xx, char cc, bool bb)
: c{cc}, b{bb}
{
if (xx < 0) throw std::runtime_error("xx < 0\n");
x = new int (xx);
}
ExceptTest(const ExceptTest &arg)
: c{arg.c}, b{arg.b}
{
x = new int(*arg.x);
}
~ExceptTest()
{
if (x != nullptr)
delete x;
}
ExceptTest(ExceptTest &&a)
:c{a.c}, b{a.b}
{
x = a.x;;
a.x = nullptr;
}
ExceptTest operator=(ExceptTest &&a)
{
delete x;
c = a.c;
b = a.c;
x = a.x;
a.x = nullptr;
return *this;
}
ExceptTest operator=(const ExceptTest &a)
{
if (this == &a)
return *this;
b = a.b;
c = a.c;
x = new int (*a.x);
return *this;
}
};
std::ostream& operator<<(std::ostream& os, const ExceptTest&t)
{
return os << *(t.x) << ' ' << t.c << ' ' << t.b;
}