10 2020 档案
摘要:https://www.hqbuy.com/dzq/wzxqy_24190997.html http://www.elecfans.com/article/88/142/2017/20171114578868.html
阅读全文
摘要:参考: https://blog.csdn.net/weixin_42731092/article/details/84533327 https://my.oschina.net/u/4308764/blog/4547012
阅读全文
摘要:参考于知乎某用户 一、格式 1、每行代码不多于80个字符; 2、使用空格,而不是制表符(Tab)来缩进,每次缩进4个字符; 3、指针符号*,引用符号&写在靠近类型的位置; 4、花括号的位置,使用Allman风格,另起一行,代码会更清晰; for (auto i = 0; i < 100; i++)
阅读全文
摘要:看一个菱形继承的例子: 家具类 / \ / \ 沙发 床 \ / \ / 沙发床 #include <iostream> #include <string> using namespace std; class CFurniture { public: CFurniture() { cout <<
阅读全文
摘要:一、纯虚函数的定义与使用 1. 在虚函数后加上=0,表示该函数不需要实现代码,也代表该类不能实例化; 2. 纯虚函数如果没有实现,那么包含该纯虚函数的类是抽象类; 3. 纯虚析构一定要有实现; 二、抽像类的概念 1. 接口类:只是该类作为父类,规范对外使用的接口(某些函数) 2. 抽象类:一定要包含
阅读全文
摘要:看一段代码: 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 class CParent { 6 public: 7 CParent() { cout << "CParent::CParent()\r\n";
阅读全文
摘要:设计模式 -- 把简单的代码复杂化 -- 方便后期维护 单例模式: 一般情况下,用户可以通过类构造很多个对象 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 class Singleton { 6 public
阅读全文
摘要:静态成员变量: 1、要单独的把实现写在类外(cpp) 2、默认会用0对该成员进行初始化 3、静态成员变量是同一个类的不同对象共用的 4、本质上是一个带类域的全局变量(CInterger::m_static = 1;) #include <iostream> #include <string> usi
阅读全文
摘要:1.作用:无法修改数据成员,一般用来修饰Get的函数 2.本质:this指针类型:const T* const 3.意义:让编译器提醒开发者该函数不能修改类的成员变量,用于const对象(引用或指针) 看一个例子: 1 #include <iostream> 2 #include <string>
阅读全文
摘要:在 C++ 中,每一个对象都能通过 this 指针来访问自己的地址。this 指针是所有成员函数的隐含参数。因此,在成员函数内部,它可以用来指向调用对象。 友元函数没有 this 指针,因为友元不是类的成员。只有成员函数才有 this 指针。 成员函数最终被编译成与对象无关的普通函数,除了成员变量,
阅读全文
摘要:函数重载 函数名相同 参数列表(个数/类型/顺序)不同 相同作用域 函数重载不考虑返回值的不同 函数隐藏 作用域不同 函数名相同 参数和返回值不考虑 函数覆盖(虚函数) 作用域不同(父子类之间的继承关系) 函数名,参数列表(参数个数/顺序/类型),返回值,调用约定必须相同 有virtual关键字 看
阅读全文
摘要:举例: 在一个聊天室里,有一群人,每个人都会说自己的话 使用一个结构把一群人表达出来 #include <stdlib.h> #include <iostream> #include <string> using namespace std; class CPerson { public: CPer
阅读全文
摘要:一、组合与继承 举例: 1 #include <iostream> 2 3 class CPerson { 4 public: 5 CPerson() {} 6 ~CPerson() {} 7 //获取性别 8 int GetGender() { 9 return m_nGender; 10 } 1
阅读全文
摘要:举个🌰 #include <stdlib.h> #include <iostream> #include <string> using namespace std; class CStudent { public: CStudent() { cout << "CStudent()\r\n"; }
阅读全文
摘要:Smart Pointer std::unique_ptr - single ownership std::shared_ptr - shared ownership std::weak_ptr - temp / no ownership 为什么使用智能指针? void bar(Entity* e)
阅读全文
摘要:举例:实现比较两个数的大小 #include <iostream> #include <string> using namespace std; #define GETMAX(a, b) ((a) > (b)) ? (a) : (b); inline int getMax(int a, int b)
阅读全文
摘要:一、作用域: 1.全局作用域 名字空间域(namespace) 2.局部作用域 块作用域 { ... } 3.类域 (class) 数据隐藏 int n = 1; int main(int argc, char const* argv[]) { int n = 2; { int n = 3; cou
阅读全文
摘要:举例:通过调用函数改变main函数里的变量的值 void foo(int m) { m = 8; } int main(int argc, char const* argv[]) { int n = 5; foo(n); return 0; } 可知,n的值不会被改变。 方法:使用指针 void f
阅读全文
摘要:举个例子: 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 #define GETMAX(a, b) ((a) > (b) ? (a) : (b)) 6 7 int getMax(int a, int b) {
阅读全文
摘要:看一个例子:在C语言中实现圆面积计算 1 #include <stdio.h> 2 3 #define PI 3.14 4 5 int main(int argc, char const *argv[]) { 6 float r = 0.5; 7 float n = PI * r * r; 8 pr
阅读全文
摘要:先看几段代码: 1 string str1 ("aaaaaaaaaa"); 2 for(auto it1 = str1.begin(); it1 != str1.end() && !str1.empty(); ++it1 ) { 3 *it1 = toupper(*it1); 4 } 5 6 str
阅读全文
摘要:1、指针本身就是一个对象,允许指针之间的拷贝与赋值,可以在其生命周期内指向不同的对象。 引用并非对象,相反的,他是为一个已经存在的对象所起的别名。操作引用即操作对象。 2、指针无需在定义时初始化,而引用需要在定义时与初始值绑定。 int val = 1024; int &refval = val;
阅读全文