diff --git a/..gitignore.un~ b/..gitignore.un~ new file mode 100644 index 0000000..c3cd99e Binary files /dev/null and b/..gitignore.un~ differ diff --git a/.com.sh.un~ b/.com.sh.un~ new file mode 100644 index 0000000..2f2003a Binary files /dev/null and b/.com.sh.un~ differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82c5d68 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +com.sh diff --git a/.gitignore~ b/.gitignore~ new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 516666b..d02aa0c 100644 --- a/README.md +++ b/README.md @@ -4,35 +4,59 @@ 学习C++内容,包括理论、实践、项目等 -目前更新: -- [x] [const那些事](./const) -- [x] [static那些事](./static) -- [x] [this那些事](./this) -- [x] [inline那些事](./inline) -- [x] [sizeof那些事](./sizeof) -- [x] [函数指针那些事](./func_pointer) -- [x] [纯虚函数和抽象类那些事](./abstract) -- [x] [vptr_vtable那些事](./vptr_vtable) -- [x] [virtual那些事](./virtual) -- [x] [volatile那些事](./volatile) -- [x] [assert那些事](./assert) -- [x] [位域那些事](./bit) -- [x] [extern那些事](./extern) -- [x] [struct那些事](./struct) -- [x] [struct与class那些事](./struct_class) -- [x] [union那些事](./union) -- [x] [c实现c++多态那些事](./c_poly) -- [x] [explicit那些事](./explicit) -- [x] [friend那些事](./friend) -- [x] [using那些事](./using) -- [x] [::那些事](./::) -- [x] [enum那些事](./enum) -- [x] [decltype那些事](./decltype) -- [x] [引用与指针那些事](./pointer_refer) -- [x] [宏那些事](./macro) +### 1.基础部分 + +- [x] [const那些事](./basic_content/const) +- [x] [static那些事](./basic_content/static) +- [x] [this那些事](./basic_content/this) +- [x] [inline那些事](./basic_content/inline) +- [x] [sizeof那些事](./basic_content/sizeof) +- [x] [函数指针那些事](./basic_content/func_pointer) +- [x] [纯虚函数和抽象类那些事](./basic_content/abstract) +- [x] [vptr_vtable那些事](./basic_content/vptr_vtable) +- [x] [virtual那些事](./basic_content/virtual) +- [x] [volatile那些事](./basic_content/volatile) +- [x] [assert那些事](./basic_content/assert) +- [x] [位域那些事](./basic_content/bit) +- [x] [extern那些事](./basic_content/extern) +- [x] [struct那些事](./basic_content/struct) +- [x] [struct与class那些事](./basic_content/struct_class) +- [x] [union那些事](./basic_content/union) +- [x] [c实现c++多态那些事](./basic_content/c_poly) +- [x] [explicit那些事](./basic_content/explicit) +- [x] [friend那些事](./basic_content/friend) +- [x] [using那些事](./basic_content/using) +- [x] [::那些事](./basic_content/::) +- [x] [enum那些事](./basic_content/enum) +- [x] [decltype那些事](./basic_content/decltype) +- [x] [引用与指针那些事](./basic_content/pointer_refer) +- [x] [宏那些事](./basic_content/macro) + +### 2.进阶部分 + +#### 2.1 effective_c++ + +正在更新... + +#### 2.2 C++2.0新特性 + +正在更新... + +#### 2.3 C++并发编程v1 + +- [第一章](./concurrency_v1/chapter1) +- [第二章](./concurrency_v1/chapter2) + +学习资料:https://chenxiaowei.gitbook.io/cpp_concurrency_in_action/ + + + +### 3.代码运行 代码运行: 全部在linux下用vim编写,使用gcc/g++调试!全部可正常运行! + + ## 关于作者: 个人公众号: diff --git a/::/:: b/basic_content/::/:: similarity index 100% rename from ::/:: rename to basic_content/::/:: diff --git a/::/::.cpp b/basic_content/::/::.cpp similarity index 100% rename from ::/::.cpp rename to basic_content/::/::.cpp diff --git a/::/README.md b/basic_content/::/README.md similarity index 100% rename from ::/README.md rename to basic_content/::/README.md diff --git a/abstract/README.md b/basic_content/abstract/README.md similarity index 100% rename from abstract/README.md rename to basic_content/abstract/README.md diff --git a/abstract/abstract.cpp b/basic_content/abstract/abstract.cpp similarity index 100% rename from abstract/abstract.cpp rename to basic_content/abstract/abstract.cpp diff --git a/abstract/derived_full.cpp b/basic_content/abstract/derived_full.cpp similarity index 100% rename from abstract/derived_full.cpp rename to basic_content/abstract/derived_full.cpp diff --git a/abstract/interesting_facts1.cpp b/basic_content/abstract/interesting_facts1.cpp similarity index 100% rename from abstract/interesting_facts1.cpp rename to basic_content/abstract/interesting_facts1.cpp diff --git a/abstract/interesting_facts2.cpp b/basic_content/abstract/interesting_facts2.cpp similarity index 100% rename from abstract/interesting_facts2.cpp rename to basic_content/abstract/interesting_facts2.cpp diff --git a/abstract/interesting_facts3.cpp b/basic_content/abstract/interesting_facts3.cpp similarity index 100% rename from abstract/interesting_facts3.cpp rename to basic_content/abstract/interesting_facts3.cpp diff --git a/abstract/interesting_facts4.cpp b/basic_content/abstract/interesting_facts4.cpp similarity index 100% rename from abstract/interesting_facts4.cpp rename to basic_content/abstract/interesting_facts4.cpp diff --git a/abstract/interesting_facts5.cpp b/basic_content/abstract/interesting_facts5.cpp similarity index 100% rename from abstract/interesting_facts5.cpp rename to basic_content/abstract/interesting_facts5.cpp diff --git a/abstract/pure_virtual.cpp b/basic_content/abstract/pure_virtual.cpp similarity index 100% rename from abstract/pure_virtual.cpp rename to basic_content/abstract/pure_virtual.cpp diff --git a/abstract/test.cpp b/basic_content/abstract/test.cpp similarity index 100% rename from abstract/test.cpp rename to basic_content/abstract/test.cpp diff --git a/assert/README.md b/basic_content/assert/README.md similarity index 100% rename from assert/README.md rename to basic_content/assert/README.md diff --git a/assert/assert b/basic_content/assert/assert similarity index 100% rename from assert/assert rename to basic_content/assert/assert diff --git a/assert/assert.c b/basic_content/assert/assert.c similarity index 100% rename from assert/assert.c rename to basic_content/assert/assert.c diff --git a/assert/iga b/basic_content/assert/iga similarity index 100% rename from assert/iga rename to basic_content/assert/iga diff --git a/assert/ignore_assert.c b/basic_content/assert/ignore_assert.c similarity index 100% rename from assert/ignore_assert.c rename to basic_content/assert/ignore_assert.c diff --git a/bit/README.md b/basic_content/bit/README.md similarity index 100% rename from bit/README.md rename to basic_content/bit/README.md diff --git a/bit/learn.cpp b/basic_content/bit/learn.cpp similarity index 100% rename from bit/learn.cpp rename to basic_content/bit/learn.cpp diff --git a/c_poly/README.md b/basic_content/c_poly/README.md similarity index 100% rename from c_poly/README.md rename to basic_content/c_poly/README.md diff --git a/c_poly/c++_examp b/basic_content/c_poly/c++_examp similarity index 100% rename from c_poly/c++_examp rename to basic_content/c_poly/c++_examp diff --git a/c_poly/c++_examp.cpp b/basic_content/c_poly/c++_examp.cpp similarity index 100% rename from c_poly/c++_examp.cpp rename to basic_content/c_poly/c++_examp.cpp diff --git a/c_poly/c_examp b/basic_content/c_poly/c_examp similarity index 100% rename from c_poly/c_examp rename to basic_content/c_poly/c_examp diff --git a/c_poly/c_examp.c b/basic_content/c_poly/c_examp.c similarity index 100% rename from c_poly/c_examp.c rename to basic_content/c_poly/c_examp.c diff --git a/const/README.md b/basic_content/const/README.md similarity index 100% rename from const/README.md rename to basic_content/const/README.md diff --git a/const/class_const/c++11_example/apple.cpp b/basic_content/const/class_const/c++11_example/apple.cpp similarity index 100% rename from const/class_const/c++11_example/apple.cpp rename to basic_content/const/class_const/c++11_example/apple.cpp diff --git a/const/class_const/c++11_example/main b/basic_content/const/class_const/c++11_example/main similarity index 100% rename from const/class_const/c++11_example/main rename to basic_content/const/class_const/c++11_example/main diff --git a/const/class_const/c++11_example/main.cpp b/basic_content/const/class_const/c++11_example/main.cpp similarity index 100% rename from const/class_const/c++11_example/main.cpp rename to basic_content/const/class_const/c++11_example/main.cpp diff --git a/const/class_const/first_example/apple.cpp b/basic_content/const/class_const/first_example/apple.cpp similarity index 100% rename from const/class_const/first_example/apple.cpp rename to basic_content/const/class_const/first_example/apple.cpp diff --git a/const/class_const/first_example/main.cpp b/basic_content/const/class_const/first_example/main.cpp similarity index 100% rename from const/class_const/first_example/main.cpp rename to basic_content/const/class_const/first_example/main.cpp diff --git a/const/class_const/overload_example/apple.cpp b/basic_content/const/class_const/overload_example/apple.cpp similarity index 100% rename from const/class_const/overload_example/apple.cpp rename to basic_content/const/class_const/overload_example/apple.cpp diff --git a/const/class_const/overload_example/main b/basic_content/const/class_const/overload_example/main similarity index 100% rename from const/class_const/overload_example/main rename to basic_content/const/class_const/overload_example/main diff --git a/const/class_const/overload_example/main.cpp b/basic_content/const/class_const/overload_example/main.cpp similarity index 100% rename from const/class_const/overload_example/main.cpp rename to basic_content/const/class_const/overload_example/main.cpp diff --git a/const/class_const/static_example/apple.cpp b/basic_content/const/class_const/static_example/apple.cpp similarity index 100% rename from const/class_const/static_example/apple.cpp rename to basic_content/const/class_const/static_example/apple.cpp diff --git a/const/class_const/static_example/main b/basic_content/const/class_const/static_example/main similarity index 100% rename from const/class_const/static_example/main rename to basic_content/const/class_const/static_example/main diff --git a/const/class_const/static_example/main.cpp b/basic_content/const/class_const/static_example/main.cpp similarity index 100% rename from const/class_const/static_example/main.cpp rename to basic_content/const/class_const/static_example/main.cpp diff --git a/const/const_function.cpp b/basic_content/const/const_function.cpp similarity index 100% rename from const/const_function.cpp rename to basic_content/const/const_function.cpp diff --git a/const/const_num.cpp b/basic_content/const/const_num.cpp similarity index 100% rename from const/const_num.cpp rename to basic_content/const/const_num.cpp diff --git a/const/extern_const/const_file1.cpp b/basic_content/const/extern_const/const_file1.cpp similarity index 100% rename from const/extern_const/const_file1.cpp rename to basic_content/const/extern_const/const_file1.cpp diff --git a/const/extern_const/const_file2.cpp b/basic_content/const/extern_const/const_file2.cpp similarity index 100% rename from const/extern_const/const_file2.cpp rename to basic_content/const/extern_const/const_file2.cpp diff --git a/const/extern_const/file1.cpp b/basic_content/const/extern_const/file1.cpp similarity index 100% rename from const/extern_const/file1.cpp rename to basic_content/const/extern_const/file1.cpp diff --git a/const/extern_const/file2.cpp b/basic_content/const/extern_const/file2.cpp similarity index 100% rename from const/extern_const/file2.cpp rename to basic_content/const/extern_const/file2.cpp diff --git a/const/funciton_const/condition1/condition1.cpp b/basic_content/const/funciton_const/condition1/condition1.cpp similarity index 100% rename from const/funciton_const/condition1/condition1.cpp rename to basic_content/const/funciton_const/condition1/condition1.cpp diff --git a/const/funciton_const/condition1/condition2.cpp b/basic_content/const/funciton_const/condition1/condition2.cpp similarity index 100% rename from const/funciton_const/condition1/condition2.cpp rename to basic_content/const/funciton_const/condition1/condition2.cpp diff --git a/const/funciton_const/condition1/condition3.cpp b/basic_content/const/funciton_const/condition1/condition3.cpp similarity index 100% rename from const/funciton_const/condition1/condition3.cpp rename to basic_content/const/funciton_const/condition1/condition3.cpp diff --git a/const/funciton_const/condition2/condition1 b/basic_content/const/funciton_const/condition2/condition1 similarity index 100% rename from const/funciton_const/condition2/condition1 rename to basic_content/const/funciton_const/condition2/condition1 diff --git a/const/funciton_const/condition2/condition1.cpp b/basic_content/const/funciton_const/condition2/condition1.cpp similarity index 100% rename from const/funciton_const/condition2/condition1.cpp rename to basic_content/const/funciton_const/condition2/condition1.cpp diff --git a/const/funciton_const/condition2/condition2.cpp b/basic_content/const/funciton_const/condition2/condition2.cpp similarity index 100% rename from const/funciton_const/condition2/condition2.cpp rename to basic_content/const/funciton_const/condition2/condition2.cpp diff --git a/const/funciton_const/condition2/condition3 b/basic_content/const/funciton_const/condition2/condition3 similarity index 100% rename from const/funciton_const/condition2/condition3 rename to basic_content/const/funciton_const/condition2/condition3 diff --git a/const/funciton_const/condition2/condition3.cpp b/basic_content/const/funciton_const/condition2/condition3.cpp similarity index 100% rename from const/funciton_const/condition2/condition3.cpp rename to basic_content/const/funciton_const/condition2/condition3.cpp diff --git a/const/funciton_const/condition3/condition1 b/basic_content/const/funciton_const/condition3/condition1 similarity index 100% rename from const/funciton_const/condition3/condition1 rename to basic_content/const/funciton_const/condition3/condition1 diff --git a/const/funciton_const/condition3/condition1.cpp b/basic_content/const/funciton_const/condition3/condition1.cpp similarity index 100% rename from const/funciton_const/condition3/condition1.cpp rename to basic_content/const/funciton_const/condition3/condition1.cpp diff --git a/decltype/README.md b/basic_content/decltype/README.md similarity index 100% rename from decltype/README.md rename to basic_content/decltype/README.md diff --git a/decltype/decltype b/basic_content/decltype/decltype similarity index 100% rename from decltype/decltype rename to basic_content/decltype/decltype diff --git a/decltype/decltype.cpp b/basic_content/decltype/decltype.cpp similarity index 100% rename from decltype/decltype.cpp rename to basic_content/decltype/decltype.cpp diff --git a/enum/README.md b/basic_content/enum/README.md similarity index 100% rename from enum/README.md rename to basic_content/enum/README.md diff --git a/enum/classic_practice b/basic_content/enum/classic_practice similarity index 100% rename from enum/classic_practice rename to basic_content/enum/classic_practice diff --git a/enum/classic_practice.cpp b/basic_content/enum/classic_practice.cpp similarity index 100% rename from enum/classic_practice.cpp rename to basic_content/enum/classic_practice.cpp diff --git a/enum/tradition_color.cpp b/basic_content/enum/tradition_color.cpp similarity index 100% rename from enum/tradition_color.cpp rename to basic_content/enum/tradition_color.cpp diff --git a/explicit/README.md b/basic_content/explicit/README.md similarity index 100% rename from explicit/README.md rename to basic_content/explicit/README.md diff --git a/explicit/explicit b/basic_content/explicit/explicit similarity index 100% rename from explicit/explicit rename to basic_content/explicit/explicit diff --git a/explicit/explicit.cpp b/basic_content/explicit/explicit.cpp similarity index 100% rename from explicit/explicit.cpp rename to basic_content/explicit/explicit.cpp diff --git a/extern/README.md b/basic_content/extern/README.md similarity index 100% rename from extern/README.md rename to basic_content/extern/README.md diff --git a/extern/extern_c++/add.c b/basic_content/extern/extern_c++/add.c similarity index 100% rename from extern/extern_c++/add.c rename to basic_content/extern/extern_c++/add.c diff --git a/extern/extern_c++/add.cpp b/basic_content/extern/extern_c++/add.cpp similarity index 100% rename from extern/extern_c++/add.cpp rename to basic_content/extern/extern_c++/add.cpp diff --git a/extern/extern_c++/add.h b/basic_content/extern/extern_c++/add.h similarity index 100% rename from extern/extern_c++/add.h rename to basic_content/extern/extern_c++/add.h diff --git a/extern/extern_c++/add.o b/basic_content/extern/extern_c++/add.o similarity index 100% rename from extern/extern_c++/add.o rename to basic_content/extern/extern_c++/add.o diff --git a/extern/extern_c++/main b/basic_content/extern/extern_c++/main similarity index 100% rename from extern/extern_c++/main rename to basic_content/extern/extern_c++/main diff --git a/extern/extern_c/add.c b/basic_content/extern/extern_c/add.c similarity index 100% rename from extern/extern_c/add.c rename to basic_content/extern/extern_c/add.c diff --git a/extern/extern_c/add.cpp b/basic_content/extern/extern_c/add.cpp similarity index 100% rename from extern/extern_c/add.cpp rename to basic_content/extern/extern_c/add.cpp diff --git a/extern/extern_c/add.h b/basic_content/extern/extern_c/add.h similarity index 100% rename from extern/extern_c/add.h rename to basic_content/extern/extern_c/add.h diff --git a/extern/extern_c/add.o b/basic_content/extern/extern_c/add.o similarity index 100% rename from extern/extern_c/add.o rename to basic_content/extern/extern_c/add.o diff --git a/extern/extern_c/main b/basic_content/extern/extern_c/main similarity index 100% rename from extern/extern_c/main rename to basic_content/extern/extern_c/main diff --git a/friend/README.md b/basic_content/friend/README.md similarity index 100% rename from friend/README.md rename to basic_content/friend/README.md diff --git a/friend/friend_class b/basic_content/friend/friend_class similarity index 100% rename from friend/friend_class rename to basic_content/friend/friend_class diff --git a/friend/friend_class.cpp b/basic_content/friend/friend_class.cpp similarity index 100% rename from friend/friend_class.cpp rename to basic_content/friend/friend_class.cpp diff --git a/friend/friend_func b/basic_content/friend/friend_func similarity index 100% rename from friend/friend_func rename to basic_content/friend/friend_func diff --git a/friend/friend_func.cpp b/basic_content/friend/friend_func.cpp similarity index 100% rename from friend/friend_func.cpp rename to basic_content/friend/friend_func.cpp diff --git a/func_pointer/func1 b/basic_content/func_pointer/func1 similarity index 100% rename from func_pointer/func1 rename to basic_content/func_pointer/func1 diff --git a/func_pointer/func_pointer.cpp b/basic_content/func_pointer/func_pointer.cpp similarity index 100% rename from func_pointer/func_pointer.cpp rename to basic_content/func_pointer/func_pointer.cpp diff --git a/img/wechat.jpg b/basic_content/img/wechat.jpg similarity index 100% rename from img/wechat.jpg rename to basic_content/img/wechat.jpg diff --git a/inline/README.md b/basic_content/inline/README.md similarity index 100% rename from inline/README.md rename to basic_content/inline/README.md diff --git a/inline/inline b/basic_content/inline/inline similarity index 100% rename from inline/inline rename to basic_content/inline/inline diff --git a/inline/inline.cpp b/basic_content/inline/inline.cpp similarity index 100% rename from inline/inline.cpp rename to basic_content/inline/inline.cpp diff --git a/inline/inline.h b/basic_content/inline/inline.h similarity index 100% rename from inline/inline.h rename to basic_content/inline/inline.h diff --git a/inline/inline_virtual.cpp b/basic_content/inline/inline_virtual.cpp similarity index 100% rename from inline/inline_virtual.cpp rename to basic_content/inline/inline_virtual.cpp diff --git a/inline/iv b/basic_content/inline/iv similarity index 100% rename from inline/iv rename to basic_content/inline/iv diff --git a/macro/README.md b/basic_content/macro/README.md similarity index 100% rename from macro/README.md rename to basic_content/macro/README.md diff --git a/macro/do_while b/basic_content/macro/do_while similarity index 100% rename from macro/do_while rename to basic_content/macro/do_while diff --git a/macro/do_while.cpp b/basic_content/macro/do_while.cpp similarity index 100% rename from macro/do_while.cpp rename to basic_content/macro/do_while.cpp diff --git a/macro/sig_examp b/basic_content/macro/sig_examp similarity index 100% rename from macro/sig_examp rename to basic_content/macro/sig_examp diff --git a/macro/sig_examp.cpp b/basic_content/macro/sig_examp.cpp similarity index 100% rename from macro/sig_examp.cpp rename to basic_content/macro/sig_examp.cpp diff --git a/pointer_refer/README.md b/basic_content/pointer_refer/README.md similarity index 100% rename from pointer_refer/README.md rename to basic_content/pointer_refer/README.md diff --git a/pointer_refer/copy_construct b/basic_content/pointer_refer/copy_construct similarity index 100% rename from pointer_refer/copy_construct rename to basic_content/pointer_refer/copy_construct diff --git a/pointer_refer/copy_construct.cpp b/basic_content/pointer_refer/copy_construct.cpp similarity index 100% rename from pointer_refer/copy_construct.cpp rename to basic_content/pointer_refer/copy_construct.cpp diff --git a/pointer_refer/effec b/basic_content/pointer_refer/effec similarity index 100% rename from pointer_refer/effec rename to basic_content/pointer_refer/effec diff --git a/pointer_refer/effec.cpp b/basic_content/pointer_refer/effec.cpp similarity index 100% rename from pointer_refer/effec.cpp rename to basic_content/pointer_refer/effec.cpp diff --git a/sizeof/README.md b/basic_content/sizeof/README.md similarity index 100% rename from sizeof/README.md rename to basic_content/sizeof/README.md diff --git a/sizeof/blackclass.cpp b/basic_content/sizeof/blackclass.cpp similarity index 100% rename from sizeof/blackclass.cpp rename to basic_content/sizeof/blackclass.cpp diff --git a/sizeof/genA.cpp b/basic_content/sizeof/genA.cpp similarity index 100% rename from sizeof/genA.cpp rename to basic_content/sizeof/genA.cpp diff --git a/sizeof/geninhe.cpp b/basic_content/sizeof/geninhe.cpp similarity index 100% rename from sizeof/geninhe.cpp rename to basic_content/sizeof/geninhe.cpp diff --git a/sizeof/moreinhe.cpp b/basic_content/sizeof/moreinhe.cpp similarity index 100% rename from sizeof/moreinhe.cpp rename to basic_content/sizeof/moreinhe.cpp diff --git a/sizeof/morevir.cpp b/basic_content/sizeof/morevir.cpp similarity index 100% rename from sizeof/morevir.cpp rename to basic_content/sizeof/morevir.cpp diff --git a/sizeof/static.cpp b/basic_content/sizeof/static.cpp similarity index 100% rename from sizeof/static.cpp rename to basic_content/sizeof/static.cpp diff --git a/sizeof/virinhe.cpp b/basic_content/sizeof/virinhe.cpp similarity index 100% rename from sizeof/virinhe.cpp rename to basic_content/sizeof/virinhe.cpp diff --git a/sizeof/virmoreinhe.cpp b/basic_content/sizeof/virmoreinhe.cpp similarity index 100% rename from sizeof/virmoreinhe.cpp rename to basic_content/sizeof/virmoreinhe.cpp diff --git a/static/README.md b/basic_content/static/README.md similarity index 100% rename from static/README.md rename to basic_content/static/README.md diff --git a/static/demo b/basic_content/static/demo similarity index 100% rename from static/demo rename to basic_content/static/demo diff --git a/static/nostatic_class.cpp b/basic_content/static/nostatic_class.cpp similarity index 100% rename from static/nostatic_class.cpp rename to basic_content/static/nostatic_class.cpp diff --git a/static/static_class.cpp b/basic_content/static/static_class.cpp similarity index 100% rename from static/static_class.cpp rename to basic_content/static/static_class.cpp diff --git a/static/static_demo.cpp b/basic_content/static/static_demo.cpp similarity index 100% rename from static/static_demo.cpp rename to basic_content/static/static_demo.cpp diff --git a/static/static_error_variable.cpp b/basic_content/static/static_error_variable.cpp similarity index 100% rename from static/static_error_variable.cpp rename to basic_content/static/static_error_variable.cpp diff --git a/static/static_funciton.cpp b/basic_content/static/static_funciton.cpp similarity index 100% rename from static/static_funciton.cpp rename to basic_content/static/static_funciton.cpp diff --git a/static/static_variable.cpp b/basic_content/static/static_variable.cpp similarity index 100% rename from static/static_variable.cpp rename to basic_content/static/static_variable.cpp diff --git a/struct/README.md b/basic_content/struct/README.md similarity index 100% rename from struct/README.md rename to basic_content/struct/README.md diff --git a/struct/ext b/basic_content/struct/ext similarity index 100% rename from struct/ext rename to basic_content/struct/ext diff --git a/struct/ext_struct_func.cpp b/basic_content/struct/ext_struct_func.cpp similarity index 100% rename from struct/ext_struct_func.cpp rename to basic_content/struct/ext_struct_func.cpp diff --git a/struct/sf b/basic_content/struct/sf similarity index 100% rename from struct/sf rename to basic_content/struct/sf diff --git a/struct/stff b/basic_content/struct/stff similarity index 100% rename from struct/stff rename to basic_content/struct/stff diff --git a/struct/struct_func b/basic_content/struct/struct_func similarity index 100% rename from struct/struct_func rename to basic_content/struct/struct_func diff --git a/struct/struct_func.c b/basic_content/struct/struct_func.c similarity index 100% rename from struct/struct_func.c rename to basic_content/struct/struct_func.c diff --git a/struct/struct_func.cpp b/basic_content/struct/struct_func.cpp similarity index 100% rename from struct/struct_func.cpp rename to basic_content/struct/struct_func.cpp diff --git a/struct/struct_func_func.cpp b/basic_content/struct/struct_func_func.cpp similarity index 100% rename from struct/struct_func_func.cpp rename to basic_content/struct/struct_func_func.cpp diff --git a/struct/stu b/basic_content/struct/stu similarity index 100% rename from struct/stu rename to basic_content/struct/stu diff --git a/struct_class/README.md b/basic_content/struct_class/README.md similarity index 100% rename from struct_class/README.md rename to basic_content/struct_class/README.md diff --git a/this/README.md b/basic_content/this/README.md similarity index 100% rename from this/README.md rename to basic_content/this/README.md diff --git a/this/img/constthis.png b/basic_content/this/img/constthis.png similarity index 100% rename from this/img/constthis.png rename to basic_content/this/img/constthis.png diff --git a/this/img/genthis.png b/basic_content/this/img/genthis.png similarity index 100% rename from this/img/genthis.png rename to basic_content/this/img/genthis.png diff --git a/this/img/thiscontrust.png b/basic_content/this/img/thiscontrust.png similarity index 100% rename from this/img/thiscontrust.png rename to basic_content/this/img/thiscontrust.png diff --git a/this/person b/basic_content/this/person similarity index 100% rename from this/person rename to basic_content/this/person diff --git a/this/person.cpp b/basic_content/this/person.cpp similarity index 100% rename from this/person.cpp rename to basic_content/this/person.cpp diff --git a/union/README.md b/basic_content/union/README.md similarity index 100% rename from union/README.md rename to basic_content/union/README.md diff --git a/union/union b/basic_content/union/union similarity index 100% rename from union/union rename to basic_content/union/union diff --git a/union/union.cpp b/basic_content/union/union.cpp similarity index 100% rename from union/union.cpp rename to basic_content/union/union.cpp diff --git a/using/README.md b/basic_content/using/README.md similarity index 100% rename from using/README.md rename to basic_content/using/README.md diff --git a/using/derived_base b/basic_content/using/derived_base similarity index 100% rename from using/derived_base rename to basic_content/using/derived_base diff --git a/using/derived_base.cpp b/basic_content/using/derived_base.cpp similarity index 100% rename from using/derived_base.cpp rename to basic_content/using/derived_base.cpp diff --git a/using/using_derived b/basic_content/using/using_derived similarity index 100% rename from using/using_derived rename to basic_content/using/using_derived diff --git a/using/using_derived.cpp b/basic_content/using/using_derived.cpp similarity index 100% rename from using/using_derived.cpp rename to basic_content/using/using_derived.cpp diff --git a/using/using_global b/basic_content/using/using_global similarity index 100% rename from using/using_global rename to basic_content/using/using_global diff --git a/using/using_global.cpp b/basic_content/using/using_global.cpp similarity index 100% rename from using/using_global.cpp rename to basic_content/using/using_global.cpp diff --git a/using/using_typedef b/basic_content/using/using_typedef similarity index 100% rename from using/using_typedef rename to basic_content/using/using_typedef diff --git a/using/using_typedef.cpp b/basic_content/using/using_typedef.cpp similarity index 100% rename from using/using_typedef.cpp rename to basic_content/using/using_typedef.cpp diff --git a/virtual/README.md b/basic_content/virtual/README.md similarity index 100% rename from virtual/README.md rename to basic_content/virtual/README.md diff --git a/virtual/set1/emp b/basic_content/virtual/set1/emp similarity index 100% rename from virtual/set1/emp rename to basic_content/virtual/set1/emp diff --git a/virtual/set1/emp.cpp b/basic_content/virtual/set1/emp.cpp similarity index 100% rename from virtual/set1/emp.cpp rename to basic_content/virtual/set1/emp.cpp diff --git a/virtual/set2/default_arg.cpp b/basic_content/virtual/set2/default_arg.cpp similarity index 100% rename from virtual/set2/default_arg.cpp rename to basic_content/virtual/set2/default_arg.cpp diff --git a/virtual/set3/copy_consrtuct.cpp b/basic_content/virtual/set3/copy_consrtuct.cpp similarity index 100% rename from virtual/set3/copy_consrtuct.cpp rename to basic_content/virtual/set3/copy_consrtuct.cpp diff --git a/virtual/set3/full_virde.cpp b/basic_content/virtual/set3/full_virde.cpp similarity index 100% rename from virtual/set3/full_virde.cpp rename to basic_content/virtual/set3/full_virde.cpp diff --git a/virtual/set3/inline_virtual.cpp b/basic_content/virtual/set3/inline_virtual.cpp similarity index 100% rename from virtual/set3/inline_virtual.cpp rename to basic_content/virtual/set3/inline_virtual.cpp diff --git a/virtual/set3/static_error.cpp b/basic_content/virtual/set3/static_error.cpp similarity index 100% rename from virtual/set3/static_error.cpp rename to basic_content/virtual/set3/static_error.cpp diff --git a/virtual/set3/vir_con.cpp b/basic_content/virtual/set3/vir_con.cpp similarity index 100% rename from virtual/set3/vir_con.cpp rename to basic_content/virtual/set3/vir_con.cpp diff --git a/virtual/set3/vir_de.cpp b/basic_content/virtual/set3/vir_de.cpp similarity index 100% rename from virtual/set3/vir_de.cpp rename to basic_content/virtual/set3/vir_de.cpp diff --git a/virtual/set3/virtual_function.cpp b/basic_content/virtual/set3/virtual_function.cpp similarity index 100% rename from virtual/set3/virtual_function.cpp rename to basic_content/virtual/set3/virtual_function.cpp diff --git a/virtual/set3/virtual_function1.cpp b/basic_content/virtual/set3/virtual_function1.cpp similarity index 100% rename from virtual/set3/virtual_function1.cpp rename to basic_content/virtual/set3/virtual_function1.cpp diff --git a/virtual/set3/virtual_inline.cpp b/basic_content/virtual/set3/virtual_inline.cpp similarity index 100% rename from virtual/set3/virtual_inline.cpp rename to basic_content/virtual/set3/virtual_inline.cpp diff --git a/virtual/set4/rtti b/basic_content/virtual/set4/rtti similarity index 100% rename from virtual/set4/rtti rename to basic_content/virtual/set4/rtti diff --git a/virtual/set4/rtti.cpp b/basic_content/virtual/set4/rtti.cpp similarity index 100% rename from virtual/set4/rtti.cpp rename to basic_content/virtual/set4/rtti.cpp diff --git a/virtual/set4/warn_rtti.cpp b/basic_content/virtual/set4/warn_rtti.cpp similarity index 100% rename from virtual/set4/warn_rtti.cpp rename to basic_content/virtual/set4/warn_rtti.cpp diff --git a/volatile/README.md b/basic_content/volatile/README.md similarity index 100% rename from volatile/README.md rename to basic_content/volatile/README.md diff --git a/volatile/noopt_vola.cpp b/basic_content/volatile/noopt_vola.cpp similarity index 100% rename from volatile/noopt_vola.cpp rename to basic_content/volatile/noopt_vola.cpp diff --git a/volatile/nv b/basic_content/volatile/nv similarity index 100% rename from volatile/nv rename to basic_content/volatile/nv diff --git a/volatile/volatile.cpp b/basic_content/volatile/volatile.cpp similarity index 100% rename from volatile/volatile.cpp rename to basic_content/volatile/volatile.cpp diff --git a/vptr_vtable/README.md b/basic_content/vptr_vtable/README.md similarity index 100% rename from vptr_vtable/README.md rename to basic_content/vptr_vtable/README.md diff --git a/vptr_vtable/img/base.jpg b/basic_content/vptr_vtable/img/base.jpg similarity index 100% rename from vptr_vtable/img/base.jpg rename to basic_content/vptr_vtable/img/base.jpg diff --git a/vptr_vtable/vptr1.cpp b/basic_content/vptr_vtable/vptr1.cpp similarity index 100% rename from vptr_vtable/vptr1.cpp rename to basic_content/vptr_vtable/vptr1.cpp diff --git a/concurrency_v1/chapter1/1_helloworld.cpp b/concurrency_v1/chapter1/1_helloworld.cpp new file mode 100644 index 0000000..069bc0d --- /dev/null +++ b/concurrency_v1/chapter1/1_helloworld.cpp @@ -0,0 +1,20 @@ +// +// Created by light on 19-11-5. +// + +#include +#include +#include + +using namespace std; + +void hello() { + cout << "hello world" << endl; +} + +int main() { + thread t(hello); + t.join(); // must add this line otherwise will failed! + // 需要注意的是线程对象执行了join后就不再joinable了,所以只能调用join一次。 + return 0; +} \ No newline at end of file diff --git a/concurrency_v1/chapter2/2.1_basic.cpp b/concurrency_v1/chapter2/2.1_basic.cpp new file mode 100644 index 0000000..8af63d1 --- /dev/null +++ b/concurrency_v1/chapter2/2.1_basic.cpp @@ -0,0 +1,108 @@ +// +// Created by light on 19-11-5. +// + +#include +#include +#include +#include + +using namespace std; + +class background_task { +public: + void operator()() const { + cout << "ok" << endl; + } +}; + +void do_something(int &i) { + cout << "do_something" << endl; +} + +struct func { + int &i; + + func(int &i_) : i(i_) {} + + void operator()() { + for (unsigned j = 0; j < 1000000; ++j) { + do_something(i); // 1. 潜在访问隐患:悬空引用 + } + } +}; + +// 特殊情况下的等待 +void f() { + int some_local_state = 0; + func my_func(some_local_state); + std::thread t(my_func); + try { +// do_something_in_current_thread(); + } + catch (...) { + t.join(); // 1 + throw; + } + t.join(); // 2 +} + +// try catch 只能捕获轻量级错误,所以如需确保线程在函数之前结束——查看是否因为线程函数使用了局部变量的引用, +// 以及其他原因——而后再确定一下程序可能会退出的途径,无论正常与否,可以提供一个简洁的机制,来做解决这个问题。 + +// 一种方式是使用“资源获取即初始化方式”(RAII,Resource Acquisition Is Initialization),并且提供一个类,在析构函数中使用join(), +// std::thread支持移动的好处是可以创建thread_guard类的实例,并且拥有其线程的所有权。 +class thread_guard { + std::thread &t; +public: + explicit thread_guard(std::thread &t_) : + t(t_) {} + + ~thread_guard() { + if (t.joinable()) // 1 + { + t.join(); // 2 + } + } + + thread_guard(thread_guard const &) = delete; // 3 + thread_guard &operator=(thread_guard const &) = delete; +}; +void f1() +{ + int some_local_state=0; + func my_func(some_local_state); + std::thread t(my_func); + thread_guard g(t); +// do_something_in_current_thread(); +} // 4 +// 当线程执行到4处时,局部对象就要被逆序销毁了。因此,thread_guard对象g是第一个被销毁的, +// 这时线程在析构函数中被加入2到原始线程中。 +// 即使do_something_in_current_thread抛出一个异常,这个销毁依旧会发生。 + + +int main() { + + background_task f; +// thread t(f); // ok +// t.join(); + //声明一个名为my_threadx的函数,这个函数带有一个参数(函数指针指向没有参数并返回background_task对象的函数),返回一个std::thread对象的函数 +// thread my_thread1(background_task()); + + // 针对Most Vexing Parse问题解决如下: +// thread my_thread1((background_task())); // 多组括号 +// my_thread1.join(); +// thread my_thread2{background_task()}; // 新的初始化语法 +// my_thread2.join(); + +// thread myThread([](){ +// cout<<"ok"< +#include + +using namespace std; + +class X { +public: + void do_length_work() {}; +}; + +void process_big_object(std::unique_ptr); + +int main() { + X my_x; + thread t(&X::do_length_work, &my_x); // 1 + + + std::unique_ptr p(new X); + p->do_length_work(); + std::thread tt(process_big_object,std::move(p)); + //std::thread实例的可移动且不可复制性。不可复制保性证了在同一时间点, + // 一个std::thread实例只能关联一个执行线程;可移动性使得程序员可以自己决定,哪个实例拥有实际执行线程的所有权。 + return 0; +} \ No newline at end of file diff --git a/concurrency_v1/chapter2/2.3_ownership.cpp b/concurrency_v1/chapter2/2.3_ownership.cpp new file mode 100644 index 0000000..cdbc4c3 --- /dev/null +++ b/concurrency_v1/chapter2/2.3_ownership.cpp @@ -0,0 +1,78 @@ +// +// Created by light on 19-11-5. +// +#include +#include +#include +#include +#include + +using namespace std; + +void some_function() {} + +void some_other_function() {} + +// std::thread不支持拷贝语义。 +// std::thread支持移动语义。 + + + +// scoped_thread实例 +void do_something(int i) { + cout << i << endl; +} + +struct func { + int &i; + + func(int &i_) : i(i_) {} + + void operator()() { + for (unsigned j = 0; j < 1000000; ++j) { + do_something(i); + } + } +}; + +class scoped_thread { + std::thread t; +public: + explicit scoped_thread(std::thread t_) : // 1 + t(std::move(t_)) { + if (!t.joinable()) // 2 + throw std::logic_error("No thread"); + } + + ~scoped_thread() { + t.join(); // 3 + } + + scoped_thread(scoped_thread const &) = delete; + + scoped_thread &operator=(scoped_thread const &) = delete; +}; + +void do_work(unsigned id) {} + +void f() { + std::vector threads; + for (unsigned i = 0; i < 20; ++i) { + threads.push_back(std::thread(do_work, i)); // 产生线程 + } + std::for_each(threads.begin(), threads.end(), + std::mem_fn(&std::thread::join)); // 对每个线程调用join() +} + +int main() { +// std::thread t1(some_function); // 构造一个thread对象t1 +// std::thread t2 = std::move(t1); // 把t1 move给另外一个thread对象t2,t1不再管理之前的线程了。 +// // 这句不需要std::move(),从临时变量进行移动是自动和隐式的。调用的是operator=(std::thread&&) +// t1 = std::thread(some_other_function); +// std::thread t3; +// t3 = std::move(t2); // 把t2 move给t3 +// // 把t3 move给t1,非法。因为`t1`已经有了一个相关的线程,会调用`std::terminate()`来终止程序。 +// t1 = std::move(t3); + f(); + return 0; +} \ No newline at end of file diff --git a/concurrency_v1/chapter2/2.4_runtime.cpp b/concurrency_v1/chapter2/2.4_runtime.cpp new file mode 100644 index 0000000..9928aa9 --- /dev/null +++ b/concurrency_v1/chapter2/2.4_runtime.cpp @@ -0,0 +1,60 @@ +// +// Created by light on 19-11-5. +// +#include +#include +#include +#include +#include + +using namespace std; + +//使得每个线程具有最小数目的元素以避免过多的线程开销 +template +struct accumulate_block { + void operator()(Iterator first, Iterator last, T &result) { + result = std::accumulate(first, last, result); + } +}; + +template +T parallel_accumlate(Iterator first, Iterator last, T init) { + unsigned long const length = std::distance(first, last); + + if (!length) + return init; + + unsigned long const min_per_thread = 25; + unsigned long const max_threads = (length + min_per_thread - 1) / min_per_thread; + cout< results(num_threads); + std::vector threads(num_threads - 1); + + Iterator block_start = first; + for (unsigned long i = 0; i < (num_threads - 1); ++i) { + Iterator block_end = block_start; + std::advance(block_end, block_size); + threads[i] = std::thread(accumulate_block(), block_start, block_end, std::ref(results[i])); + block_start = block_end; + } + accumulate_block()(block_start, last, results[num_threads - 1]); + std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join)); + + return std::accumulate(results.begin(), results.end(), init); +} + + +int main() { + + vector v{3,4,5,6}; + int res=0; + cout< +#include + +using namespace std; + + +// 线程的通用标识符 +std::thread::id master_thread; + +void do_master_thread_work() { + cout << "master" << endl; +} + +void do_common_work() { + cout << "common" << endl; +} + +void some_core_part_of_algorithm() { + if (std::this_thread::get_id() == master_thread) { + do_master_thread_work(); + } + do_common_work(); +} + +int main() { + std::cout << std::this_thread::get_id() << endl; + thread t(some_core_part_of_algorithm); + t.join(); + return 0; +} \ No newline at end of file diff --git a/effective_c++/2.cpp b/effective_c++/2.cpp new file mode 100644 index 0000000..428f3b1 --- /dev/null +++ b/effective_c++/2.cpp @@ -0,0 +1,50 @@ +// +// Created by light on 19-9-11. +// + +#include + +using namespace std; +struct A { +#define p "hello" +}; + +class C { +public: + // static const 可以直接在类内部初始化 + // no-const static 只能在外面初始化 + static const int NUM = 3; //声明 + enum con { + NUM1 = 3 + }; +}; + +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +template +inline int Max(const T& a, const T& b){ + return (a>b ? a:b); +} +const int C::NUM; // 定义 +int main() { + cout << p << endl; // macro is global + C c; + cout << &c.NUM << endl; // 未定义的引用,需要定义 + + cout << C::NUM1 << endl; +// cout << &C:NUM1 << endl; //error enum no address + + int a=5, b=0; + cout<