This commit is contained in:
Light-City 2019-12-09 11:14:25 +08:00
parent f98a4ce2c2
commit 3ae20ae621
6 changed files with 49 additions and 3 deletions

View File

@ -132,7 +132,8 @@ for(decl:col) {
#### 3.1 [极客时间《现代C++实战30讲》](https://time.geekbang.org/channel/home) #### 3.1 [极客时间《现代C++实战30讲》](https://time.geekbang.org/channel/home)
- [堆、栈、RAIIC++里该如何管理资源?](./morden_C++_30) - [堆、栈、RAIIC++里该如何管理资源?](./morden_C++_30)
- [堆与栈](./morden_C++_30/RAII/heap_stack.cpp) - [](./morden_C++_30/RAII/heap.cpp)
- [](./morden_C++_30/RAII/stack.cpp)
- [RAII](./morden_C++_30/RAII/RAII.cpp) - [RAII](./morden_C++_30/RAII/RAII.cpp)
### 4.代码运行 ### 4.代码运行

Binary file not shown.

View File

@ -3,5 +3,7 @@ project(Morden_C++)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
add_executable(heap_stack_RAII RAII/heap_stack.cpp) add_executable(heap RAII/heap.cpp)
add_executable(stack RAII/stack.cpp)
add_executable(RAII RAII/RAII.cpp) add_executable(RAII RAII/RAII.cpp)
add_executable(auto_ptr smart_ptr/auto_ptr.cpp)

View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.14)
project(Morden_C++)
set(CMAKE_CXX_STANDARD 11)
# boost
set(BOOST_INCLUDE_DIR /home/light/bst/include)
set(BOOST_LINK_DIR /home/light/bst/lib)
# gcc/clang -I(i的大写字母)
include_directories(${BOOST_INCLUDE_DIR})
# .so .dll .dylib gcc -L
link_directories(${BOOST_LINK_DIR})
add_executable(heap RAII/heap.cpp)
add_executable(stack RAII/stack.cpp)
add_executable(RAII RAII/RAII.cpp)
add_executable(auto_ptr smart_ptr/auto_ptr.cpp)

View File

@ -0,0 +1,26 @@
//
// Created by light on 19-12-9.
//
#include <iostream>
class Obj {
public:
Obj() { puts("Obj()"); }
~Obj() { puts("~Obj()"); }
};
void foo(int n)
{
Obj obj;
if (n == 42)
throw "life, the universe and everything";
}
// 不管是否发生了异常obj 的析构函数都会得到执行。
int main()
{
try {
foo(41);
foo(42);
}
catch (const char* s) {
puts(s);
}
}