update
This commit is contained in:
parent
f98a4ce2c2
commit
3ae20ae621
@ -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)
|
||||||
|
|
||||||
- [堆、栈、RAII:C++里该如何管理资源?](./morden_C++_30)
|
- [堆、栈、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)
|
- [RAII](./morden_C++_30/RAII/RAII.cpp)
|
||||||
|
|
||||||
### 4.代码运行
|
### 4.代码运行
|
||||||
|
BIN
morden_C++_30/.CMakeLists.txt.un~
Normal file
BIN
morden_C++_30/.CMakeLists.txt.un~
Normal file
Binary file not shown.
@ -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)
|
||||||
|
17
morden_C++_30/CMakeLists.txt~
Normal file
17
morden_C++_30/CMakeLists.txt~
Normal 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)
|
26
morden_C++_30/RAII/stack.cpp
Normal file
26
morden_C++_30/RAII/stack.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user