C++11 新特性

C++11新特性

C++11 新特性

https://harttle.land/2015/10/08/cpp11.html

C++11新特性:右值引用与move语义

https://www.tianmaying.com/tutorial/cpp11-right-value

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

// C++11新特性:右值引用与move语义

#include <iostream>
using namespace std;

class Person
{
public:
Person(const char* name){
std::cout << "Person constructor" << "\n";
size_t len = strlen(name) + 1;
_name = new char[len];
memcpy(_name , name , len);
}
Person(const Person& p){
std::cout << "Person copy constructor" << "\n";
size_t len = strlen(p._name) + 1;
_name = new char[len];
memcpy(_name , p._name, len);
}
Person(Person&& per){
std::cout << "Person move copy constructor" << "\n";
_name = per._name;
per._name = nullptr;
}
Person& operator=(const Person &per){
std::cout << "Person copy operator" << "\n";
size_t len = strlen(per._name) + 1;
_name = new char [len];
memcpy(_name , per._name , len);
return *this;
}
Person& operator=(Person &&per){
std::cout << "Person move copy operator" << "\n";
if(_name) delete [] _name;
_name = per._name;
per._name = nullptr;
return *this;
}
~Person(){
std::cout << "Person distructor" << "\n";
if(_name) delete []_name;
}
private:
char * _name;
};

Person getPerson(){
Person p("Jack");
return p;
}

int main(int argc, char const *argv[])
{
int c1;
std::cout << typeid(c1).name() << "\n";
decltype(auto) c2 = c1;
std::cout << typeid(c2).name() << "\n";
std::cout << "----------------------" << "\n";
Person a = getPerson();
std::cout << "----------------------" << "\n";
a = getPerson();
std::cout << "----------------------" << "\n";
return 0;

}

C++11特性:decltype关键字

https://www.cnblogs.com/QG-whz/p/4952980.html

RVO-编译器返回值优化 - Effective C++ 20

https://blog.csdn.net/gatieme/article/details/22650353

C++ 资源大全

https://www.cplusplus.me/2182.html

多线程死锁问题