2021年10月6日

摘要: 折半查找 int arr[] = { 23, 37, 41, 55, 64, 75, 83, 99, 101 }; int t; cin >> t; int low = 0, high = sizeof(arr) / sizeof(arr[0]); int mid = 0; while (low < 阅读全文
posted @ 2021-10-06 21:53 祁东 阅读(3) 评论(0) 推荐(0) 编辑
 
摘要: =default&=delete class Foo { public: Foo(int i) :_i(i) { cout << "Foo(int i)\n"; } Foo() = default; //可以跟上一个构造函数并存(构造函数可以多个并存) Foo(const Foo& x) :_i(x 阅读全文
posted @ 2021-10-06 10:51 祁东 阅读(13) 评论(0) 推荐(0) 编辑
 
摘要: 构造函数可以有多个,但是拷贝构造函数只能有一个。 当类有指针成员时,必写Big-three函数 浅拷贝:拷贝指针四字节;深拷贝:拷贝指针四字节和指针指向的数据 define和const区别 - 菜鸟 define/typedef/using - 博客园 不能对Alias Template(化名)做偏 阅读全文
posted @ 2021-10-06 10:50 祁东 阅读(14) 评论(0) 推荐(0) 编辑

2021年10月5日

摘要: 数量不定的参数模板 void print() { } //...就是pack(包) template<typename T, typename... Types> //print(7.5,"hello",bitset<16>(377),42); ...部分就是{"hello",bitset<16>( 阅读全文
posted @ 2021-10-05 19:07 祁东 阅读(16) 评论(0) 推荐(0) 编辑

2021年10月1日

摘要: 大括号可以设置初始值 大括号设置初始值 int i; int j{}; //初始值为0 int* p; int* q{}; //初始值为nullptr cout << i << " " << j << " " << p << " " << q << endl; //使用了未初始化的局部变量“i” / 阅读全文
posted @ 2021-10-01 16:42 祁东 阅读(5) 评论(0) 推荐(0) 编辑

2021年9月30日

摘要: auto类型一定在声明时初始化 C++11新for语法:for(auto i: vec(容器)) 引用后的别名不能更改指向,只能改变内容 虚机制:有虚函数的类,内存会比没有虚函数多4个字节;继承函数,不是继承内存大小,继承的是调用权(静态绑定/动态绑定) 阅读全文
posted @ 2021-09-30 23:00 祁东 阅读(24) 评论(0) 推荐(0) 编辑

2021年9月29日

摘要: 调用函数模板时不必指定类型 阅读全文
posted @ 2021-09-29 22:36 祁东 阅读(67) 评论(0) 推荐(0) 编辑

2021年9月28日

摘要: string类 class String { public: String(const char* cstr=0); String(const String& str); String& operator=(const String& str); ~String(); char* get_c_str 阅读全文
posted @ 2021-09-28 22:20 祁东 阅读(25) 评论(0) 推荐(0) 编辑
 
摘要: new :先分配内存,载调用构造函数,delete与new恰好相反 调用析构函数delete删除的内容为? 静态函数没有this指针,只能处理静态变量 不会造成浪费 复合的构造和析构函数调用顺序: default(默认)构造函数当有多个时,要声明调用哪个 复合:非指针(classname class 阅读全文
posted @ 2021-09-28 21:59 祁东 阅读(16) 评论(0) 推荐(0) 编辑

2021年9月27日

摘要: 对象的常量函数 class complex { public: complex(double r, double i = 0):re(r), im(i) {} complex() :re(1), im(0) {} complex& operator += (const complex&); //返回 阅读全文
posted @ 2021-09-27 23:47 祁东 阅读(22) 评论(0) 推荐(0) 编辑