Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Light-City committed Dec 9, 2019
1 parent f98a4ce commit 3ae20ae
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ for(decl:col) {
#### 3.1 [极客时间《现代C++实战30讲》](https://time.geekbang.org/channel/home)

- [堆、栈、RAII:C++里该如何管理资源?](./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)

### 4.代码运行
Expand Down
Binary file added morden_C++_30/.CMakeLists.txt.un~
Binary file not shown.
6 changes: 4 additions & 2 deletions morden_C++_30/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ project(Morden_C++)

set(CMAKE_CXX_STANDARD 11)

add_executable(heap_stack_RAII RAII/heap_stack.cpp)
add_executable(RAII RAII/RAII.cpp)
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)
17 changes: 17 additions & 0 deletions morden_C++_30/CMakeLists.txt~
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
26 changes: 26 additions & 0 deletions morden_C++_30/RAII/stack.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 3ae20ae

Please sign in to comment.