Skip to content

Commit 3ae20ae

Browse files
committed
update
1 parent f98a4ce commit 3ae20ae

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ for(decl:col) {
132132
#### 3.1 [极客时间《现代C++实战30讲》](https://time.geekbang.org/channel/home)
133133

134134
- [堆、栈、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)
136137
- [RAII](./morden_C++_30/RAII/RAII.cpp)
137138

138139
### 4.代码运行

Diff for: morden_C++_30/.CMakeLists.txt.un~

861 Bytes
Binary file not shown.

Diff for: morden_C++_30/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ project(Morden_C++)
33

44
set(CMAKE_CXX_STANDARD 11)
55

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)

Diff for: morden_C++_30/CMakeLists.txt~

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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.

Diff for: morden_C++_30/RAII/stack.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)