From 994963d919f4a8e879a060db888870858d775a3b Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 2 Aug 2023 19:22:52 +0800 Subject: [PATCH] day7 --- README.md | 6 ++++++ day8/stl_code/d4.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 day8/stl_code/d4.cpp diff --git a/README.md b/README.md index b3ff383..7f55c90 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,9 @@ #### day3: 对象的构造与析构, 构造函数的分类与调用, 拷贝构造函数的调用时机, 构造函数的调用规则, 深拷贝和浅拷贝, 多个对象的构造和析构(初始化列表, 类对象作为成员), explicit 关键字(禁止隐式转换), 动态创建对象(malloc/realloc/calloc 在堆中创建空间, new 关键字), 扩展 new 和 delete, #### day4: static 静态成员, 类的单例设计模式, 对象的存储(this 指针与链式编程, const 修饰成员函数与类对象), 友元, 运算符重载 + +#### day5: =运算符的重载, () 函数调用重载, `注意: &&和|| 无法重载`, + +#### day6: 多继承(同属一个超级父类)产生的问题, 多态,抽象类, 虚函数(virtual)与纯虚函数, 接口类的多继承, override-overload-redefined 的区别, 函数模版, 普通函数与带泛型函数的区别 + +#### day7: 函数模板, 类模板, 类模板与友元一起使用的情况, 类型转换函数(static_cast, dynamic_cast, const_cast, reinterpret_cast) diff --git a/day8/stl_code/d4.cpp b/day8/stl_code/d4.cpp new file mode 100644 index 0000000..f83c391 --- /dev/null +++ b/day8/stl_code/d4.cpp @@ -0,0 +1,51 @@ +// vector 的嵌套使用示例 +#include + +using namespace std; + +int main() +{ + vector > vs; // 嵌套容器 + vector v1, v2, v3; + + for (int i = 0; i < 9; i++) + { + switch (i / 3) + { + case 0: + v1.push_back(i + 1); + break; + case 1: + v2.push_back(i + 1); + break; + case 2: + v3.push_back(i + 1); + break; + } + } + + vs.push_back(v1); + vs.push_back(v2); + vs.push_back(v3); + // for (int i = 0; i < vs.size(); i++) + // { + // for (int j = 0; j < vs[i].size(); j++) + // { + // cout << vs[i][j] << " "; + // } + // cout << endl; + // } + + vector >::iterator it; + for (it = vs.begin(); it != vs.end(); it++) + { + vector::iterator it2; + for (it2 = (*it).begin(); it2 != (*it).end(); it2++) + { + cout << *it2 << " "; + } + cout << endl; + } + + return 0; +}