forked from Light-City/CPlusPlusThings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobj3.cpp
More file actions
48 lines (38 loc) · 708 Bytes
/
Copy pathobj3.cpp
File metadata and controls
48 lines (38 loc) · 708 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
//
// Created by light on 19-12-22.
//
#include <iostream>
using namespace std;
// Can copy and move
class A {
public:
A() { cout << "Create A\n"; }
~A() { cout << "Destroy A\n"; }
A(const A &) { cout << "Copy A\n"; }
A(A &&) { cout << "Move A\n"; }
A &operator=(const A &a) {
std::cout << "copy assignment" << std::endl;
return *this;
}
A &operator=(A &&a) {
cout << "move assignment\n";
return *this;
}
};
// 编译器无法优化
A getA_duang() {
A a1;
A a2;
if (rand() > 42) {
return a1;
} else {
return a2;
}
}
int main() {
// cout<<"拷贝"<<endl;
// auto a = getA_duang();
cout << "赋值" << endl;
A aa;
aa = getA_duang();
}