-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest.cpp
More file actions
48 lines (37 loc) · 771 Bytes
/
test.cpp
File metadata and controls
48 lines (37 loc) · 771 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
#include <algorithm>
#include <vector>
class A {
mutable int m;
public:
A() : m(0) {}
explicit A(int m) : m(m) {}
A(const A &other) : m(other.m) { other.m = 0; } // NON_COMPLIANT
A &operator=(const A &other) { // NON_COMPLIANT
if (&other != this) {
m = other.m;
other.m = 0;
}
return *this;
}
int get_m() const { return m; }
};
class B {
int m;
public:
B() : m(0) {}
explicit B(int m) : m(m) {}
B(const B &other) : m(other.m) {}
B(B &&other) : m(other.m) { other.m = 0; }
B &operator=(const B &other) { // COMPLIANT
if (&other != this) {
m = other.m;
}
return *this;
}
B &operator=(B &&other) {
m = other.m;
other.m = 0;
return *this;
}
int get_m() const { return m; }
};