摘要: 1.List class MM { public: MM(string name, int age) :name(name), age(age) {} string getName() const{ return name; } int getAge() const{ return age; } p 阅读全文
posted @ 2021-09-07 22:39 Creature_lurk 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 1.vector void testCreateVector() { vector<int> vi; //构造时没有标长度不能直接用下表法访问 //vi[0]=1; vi = { 1,2,3,4 }; vector<string> vs = { "Hello","Hi","loveyou" }; v 阅读全文
posted @ 2021-09-07 18:55 Creature_lurk 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 1.array myArray.hpp //定义和实现写在一起的时候,用hpp #include <iostream> using namespace std; template <class T, size_t _size> class MyArray { public: MyArray() { 阅读全文
posted @ 2021-09-07 12:51 Creature_lurk 阅读(38) 评论(0) 推荐(0) 编辑
摘要: 1.可变参模板函数 //列表方式展开 template<class _Ty> void print(_Ty data) { cout << data << endl; } template<class ...Args> void printData(Args... args) { int array 阅读全文
posted @ 2021-09-06 23:24 Creature_lurk 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 1.函数模板 //普通与模板同时存在的时候,优先使用普通函数 int Max(int a, int b) { return a > b ? a : b; } template <typename _Ty> _Ty Max(_Ty a, _Ty b) { return a > b ? a : b; } 阅读全文
posted @ 2021-09-06 21:38 Creature_lurk 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 1.虚析构函数 class MM { public: virtual void print() { cout << "MM" << endl; } virtual ~MM() { cout << "~MM" << endl; } }; class Girl:public MM { public: v 阅读全文
posted @ 2021-09-06 20:59 Creature_lurk 阅读(35) 评论(0) 推荐(0) 编辑
摘要: 1.虚函数 + 在类中用virtual 修饰的函数 叫做虚函数+ 没有虚构造函数,但是存在虚析构函数 虚函数对于类的类内存影响 + 没有数据成员类是占用1个字节,普通函数对于类的内存是毫无影响 + 所有虚函数都是用一个指针存储:虚函数指针 + 通过虚函数表的理解去访问虚函数 class MM { p 阅读全文
posted @ 2021-09-06 20:13 Creature_lurk 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 1.类的继承中的同名问题 1.1正常继承中的同名问题 基本上C++同名问题都是就近原则 如果想访问父类成员,用类名限定即可。 2.虚继承(菱形继承) A >int a; B C B、C继承自A,D多继承于B、C >B:a C:a //B,C要虚继承A D >D: a a class A { publ 阅读全文
posted @ 2021-09-06 18:29 Creature_lurk 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 1.继承的传递性 继承具有传递性:无论继承多少次,属性都存在 2.多继承 class A { public: A(string name1, string name2) :name1(name1), name2(name2) {} protected: string name1; string na 阅读全文
posted @ 2021-09-06 17:44 Creature_lurk 阅读(52) 评论(0) 推荐(0) 编辑
摘要: 1.基本概念 继承: 父类 子类 ,子类没产生新的东西 派生:基类 派生类 继承A 产生B ,A B 2.继承的实质 父类的属性在子类中也存在一份,构造函数不能被继承 3.继承的权限问题 | | public | protected | private || | | | || public继承 | 阅读全文
posted @ 2021-09-06 11:08 Creature_lurk 阅读(28) 评论(0) 推荐(0) 编辑