forked from Light-City/CPlusPlusThings
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoexcept.cpp
More file actions
Latest commit
26 lines (19 loc) · 774 Bytes
/
Copy pathnoexcept.cpp
File metadata and controls
26 lines (19 loc) · 774 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
//
// Created by light on 19-11-3.
//
#include<iostream>
#include<vector>
usingnamespacestd;
// noexcepte ()中可以加条件
// 异常可传递 a调用b b抛出异常,a没处理,就会抛出异常
// 1.异常的回传机制:调用foo如果抛出异常,foo会接着往上层抛出异常,
// 如果最上层没有处理,则会调用terminate函数,terminate函数内部调用abort,使程序退出
// 2.在使用vector deque等容器的移动构造和移动赋值的时候,如果移动构造和移动赋值没有加上noexcept,
// 则容器增长的时候不会调用move constructor,效率就会偏低,所以后面需要加上noexcept,安心使用。
voidfoo() noexcept(true) {
}
intmain() {
foo();
vector<int> vec;
return0;
}