随笔分类 -  C++

摘要:看一个例子: 1 #include <iostream> 2 3 using namespace std; 4 5 #define LEN 10 6 7 int len_foo() { 8 return 5; 9 } 10 11 int main() { 12 char arr_1[10]; 13 阅读全文
posted @ 2020-11-05 16:39 朱果果 阅读(833) 评论(0) 推荐(0)
摘要:转载:https://www.jianshu.com/p/3c95b0471d3a 1 // 不要用第四个参数传自定的数据,当av_read_frame的时候会出问题,无限循环 2 avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buf 阅读全文
posted @ 2020-11-03 12:21 朱果果 阅读(5280) 评论(0) 推荐(0)
摘要:一、运算符重载 运算符重载(Operator Overloading):让一个运算符可以有不同的功能。 已经熟知的运算符重载,如‘+’,可以对不同类型的(int,float)的数据进行加法操作;'<<’既是位移运算符,又可以配合 cout 向控制台输出数据。 C++允许程序员自己重载运算符。 以下代 阅读全文
posted @ 2020-11-01 23:42 朱果果 阅读(1349) 评论(0) 推荐(0)
摘要:参考于知乎某用户 一、格式 1、每行代码不多于80个字符; 2、使用空格,而不是制表符(Tab)来缩进,每次缩进4个字符; 3、指针符号*,引用符号&写在靠近类型的位置; 4、花括号的位置,使用Allman风格,另起一行,代码会更清晰; for (auto i = 0; i < 100; i++) 阅读全文
posted @ 2020-10-18 19:14 朱果果 阅读(1789) 评论(0) 推荐(0)
摘要:看一个菱形继承的例子: 家具类 / \ / \ 沙发 床 \ / \ / 沙发床 #include <iostream> #include <string> using namespace std; class CFurniture { public: CFurniture() { cout << 阅读全文
posted @ 2020-10-17 20:57 朱果果 阅读(195) 评论(0) 推荐(0)
摘要:一、纯虚函数的定义与使用 1. 在虚函数后加上=0,表示该函数不需要实现代码,也代表该类不能实例化; 2. 纯虚函数如果没有实现,那么包含该纯虚函数的类是抽象类; 3. 纯虚析构一定要有实现; 二、抽像类的概念 1. 接口类:只是该类作为父类,规范对外使用的接口(某些函数) 2. 抽象类:一定要包含 阅读全文
posted @ 2020-10-17 18:47 朱果果 阅读(162) 评论(0) 推荐(0)
摘要:看一段代码: 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 class CParent { 6 public: 7 CParent() { cout << "CParent::CParent()\r\n"; 阅读全文
posted @ 2020-10-16 17:46 朱果果 阅读(141) 评论(0) 推荐(0)
摘要:设计模式 -- 把简单的代码复杂化 -- 方便后期维护 单例模式: 一般情况下,用户可以通过类构造很多个对象 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 class Singleton { 6 public 阅读全文
posted @ 2020-10-16 15:27 朱果果 阅读(369) 评论(0) 推荐(0)
摘要:静态成员变量: 1、要单独的把实现写在类外(cpp) 2、默认会用0对该成员进行初始化 3、静态成员变量是同一个类的不同对象共用的 4、本质上是一个带类域的全局变量(CInterger::m_static = 1;) #include <iostream> #include <string> usi 阅读全文
posted @ 2020-10-16 11:56 朱果果 阅读(227) 评论(0) 推荐(0)
摘要:1.作用:无法修改数据成员,一般用来修饰Get的函数 2.本质:this指针类型:const T* const 3.意义:让编译器提醒开发者该函数不能修改类的成员变量,用于const对象(引用或指针) 看一个例子: 1 #include <iostream> 2 #include <string> 阅读全文
posted @ 2020-10-15 18:48 朱果果 阅读(854) 评论(0) 推荐(0)
摘要:在 C++ 中,每一个对象都能通过 this 指针来访问自己的地址。this 指针是所有成员函数的隐含参数。因此,在成员函数内部,它可以用来指向调用对象。 友元函数没有 this 指针,因为友元不是类的成员。只有成员函数才有 this 指针。 成员函数最终被编译成与对象无关的普通函数,除了成员变量, 阅读全文
posted @ 2020-10-15 18:36 朱果果 阅读(122) 评论(0) 推荐(0)
摘要:函数重载 函数名相同 参数列表(个数/类型/顺序)不同 相同作用域 函数重载不考虑返回值的不同 函数隐藏 作用域不同 函数名相同 参数和返回值不考虑 函数覆盖(虚函数) 作用域不同(父子类之间的继承关系) 函数名,参数列表(参数个数/顺序/类型),返回值,调用约定必须相同 有virtual关键字 看 阅读全文
posted @ 2020-10-15 17:40 朱果果 阅读(1161) 评论(0) 推荐(0)
摘要:举例: 在一个聊天室里,有一群人,每个人都会说自己的话 使用一个结构把一群人表达出来 #include <stdlib.h> #include <iostream> #include <string> using namespace std; class CPerson { public: CPer 阅读全文
posted @ 2020-10-15 12:28 朱果果 阅读(167) 评论(0) 推荐(0)
摘要:一、组合与继承 举例: 1 #include <iostream> 2 3 class CPerson { 4 public: 5 CPerson() {} 6 ~CPerson() {} 7 //获取性别 8 int GetGender() { 9 return m_nGender; 10 } 1 阅读全文
posted @ 2020-10-15 10:23 朱果果 阅读(149) 评论(0) 推荐(0)
摘要:举个🌰 #include <stdlib.h> #include <iostream> #include <string> using namespace std; class CStudent { public: CStudent() { cout << "CStudent()\r\n"; } 阅读全文
posted @ 2020-10-15 09:12 朱果果 阅读(133) 评论(0) 推荐(0)
摘要:Smart Pointer std::unique_ptr - single ownership std::shared_ptr - shared ownership std::weak_ptr - temp / no ownership 为什么使用智能指针? void bar(Entity* e) 阅读全文
posted @ 2020-10-14 17:55 朱果果 阅读(210) 评论(0) 推荐(0)
摘要:举例:实现比较两个数的大小 #include <iostream> #include <string> using namespace std; #define GETMAX(a, b) ((a) > (b)) ? (a) : (b); inline int getMax(int a, int b) 阅读全文
posted @ 2020-10-14 16:21 朱果果 阅读(208) 评论(0) 推荐(0)
摘要:一、作用域: 1.全局作用域 名字空间域(namespace) 2.局部作用域 块作用域 { ... } 3.类域 (class) 数据隐藏 int n = 1; int main(int argc, char const* argv[]) { int n = 2; { int n = 3; cou 阅读全文
posted @ 2020-10-14 15:43 朱果果 阅读(475) 评论(0) 推荐(0)
摘要:举例:通过调用函数改变main函数里的变量的值 void foo(int m) { m = 8; } int main(int argc, char const* argv[]) { int n = 5; foo(n); return 0; } 可知,n的值不会被改变。 方法:使用指针 void f 阅读全文
posted @ 2020-10-14 14:39 朱果果 阅读(111) 评论(0) 推荐(0)
摘要:举个例子: 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) { 阅读全文
posted @ 2020-10-14 11:27 朱果果 阅读(292) 评论(0) 推荐(0)