File tree Expand file tree Collapse file tree 6 files changed +49
-3
lines changed Expand file tree Collapse file tree 6 files changed +49
-3
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,8 @@ for(decl:col) {
132
132
#### 3.1 [ 极客时间《现代C++实战30讲》] ( https://time.geekbang.org/channel/home )
133
133
134
134
- [ 堆、栈、RAII:C++里该如何管理资源?] ( ./morden_C++_30 )
135
- - [ 堆与栈] ( ./morden_C++_30/RAII/heap_stack.cpp )
135
+ - [ 堆] ( ./morden_C++_30/RAII/heap.cpp )
136
+ - [ 栈] ( ./morden_C++_30/RAII/stack.cpp )
136
137
- [ RAII] ( ./morden_C++_30/RAII/RAII.cpp )
137
138
138
139
### 4.代码运行
Original file line number Diff line number Diff line change @@ -3,5 +3,7 @@ project(Morden_C++)
3
3
4
4
set (CMAKE_CXX_STANDARD 11 )
5
5
6
- add_executable (heap_stack_RAII RAII/heap_stack.cpp )
7
- add_executable (RAII RAII/RAII.cpp )
6
+ add_executable (heap RAII/heap.cpp )
7
+ add_executable (stack RAII/stack.cpp )
8
+ add_executable (RAII RAII/RAII.cpp )
9
+ add_executable (auto_ptr smart_ptr/auto_ptr.cpp )
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required(VERSION 3.14)
2
+ project(Morden_C++)
3
+
4
+ set(CMAKE_CXX_STANDARD 11)
5
+ # boost
6
+ set(BOOST_INCLUDE_DIR /home/light/bst/include)
7
+ set(BOOST_LINK_DIR /home/light/bst/lib)
8
+
9
+ # 去哪里找头文件 相当于gcc/clang 中的-I(i的大写字母)参数
10
+ include_directories(${BOOST_INCLUDE_DIR})
11
+ # 去哪里找库文件 .so .dll .dylib 相当于gcc 中的-L参数
12
+ link_directories(${BOOST_LINK_DIR})
13
+
14
+ add_executable(heap RAII/heap.cpp)
15
+ add_executable(stack RAII/stack.cpp)
16
+ add_executable(RAII RAII/RAII.cpp)
17
+ add_executable(auto_ptr smart_ptr/auto_ptr.cpp)
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by light on 19-12-9.
3
+ //
4
+ #include < iostream>
5
+ class Obj {
6
+ public:
7
+ Obj () { puts (" Obj()" ); }
8
+ ~Obj () { puts (" ~Obj()" ); }
9
+ };
10
+ void foo (int n)
11
+ {
12
+ Obj obj;
13
+ if (n == 42 )
14
+ throw " life, the universe and everything" ;
15
+ }
16
+ // 不管是否发生了异常,obj 的析构函数都会得到执行。
17
+ int main ()
18
+ {
19
+ try {
20
+ foo (41 );
21
+ foo (42 );
22
+ }
23
+ catch (const char * s) {
24
+ puts (s);
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments