forked from Light-City/CPlusPlusThings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobj2.cpp
More file actions
46 lines (34 loc) · 685 Bytes
/
Copy pathobj2.cpp
File metadata and controls
46 lines (34 loc) · 685 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
//
// Created by light on 19-12-22.
//
// nrvo example
#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_named() {
A a;
return a;
}
int main() {
// cout<<"拷贝"<<endl;
// auto a = getA_named();
cout << "赋值" << endl;
A aa;
aa = getA_named();
}