C++
C++ primer
17231
这个作者很懒,什么都没留下…
展开
-
c++访问
可见,c++中通过a的signature去匹配B及B的父类,找到第一个匹配signature的method。原创 2022-11-16 17:29:08 · 250 阅读 · 0 评论 -
c++ 类的隐式转换,构造函数,拷贝构造函数
none原创 2022-11-02 16:55:49 · 217 阅读 · 0 评论 -
Leetcode 179. 最大数
cmp仿函数原创 2022-10-22 12:51:48 · 111 阅读 · 0 评论 -
面试题 17.26. 稀疏相似度
char str[256]可以被push_back进vector\ ans原创 2022-10-11 20:28:59 · 146 阅读 · 0 评论 -
Leetcode 面试题 17.20. 连续中值
multiset.insert()原创 2022-10-05 17:54:14 · 117 阅读 · 0 评论 -
decltype、变量与指针
#include<iostream>using namespace std;int main() { int a, * p = &a; decltype(a) t1; decltype(p) t2; decltype(*p) t3;//*+decltype ==> 引用变量 ==> 需要初始化 decltype((a)) t4;//()+decltype ==> 引用变量 ==> 需要初始值 return 0;...原创 2021-08-30 16:10:29 · 130 阅读 · 0 评论 -
C++对齐规则
对齐基数在gcc中通过预编译指令#pragma pack(n),n = 1,2,4,8,16设定,对齐规则如下:成员相对于首地址的偏移量需要被该成员大小与对齐基数中较小者整除。 整个结构体大小需要被最宽成员大小与对齐基数中较小者整除。...原创 2021-10-13 11:52:21 · 244 阅读 · 0 评论 -
继承的构造函数
#include"iostream"using namespace std;class Base {public: int b; Base() { b=1; }; Base(int b_) { b = b_; };};class D1 :public Base {public: int d{0}; D1(int b_) :Base(b_){} //没有这句D1 d(2)会报错};int main() { D1 d(2); cout << d.b; re.原创 2021-09-03 16:52:01 · 54 阅读 · 0 评论 -
虚函数与作用域cpp P550
#include"iostream"class Base {public: virtual int fcn() { return 0; };};class D1 :public Base {public: int fcn(int) { return 0; }; virtual void f2() {};};class D2 :public D1 {public: int fcn(int) { return 0; }; int fcn() { re...原创 2021-09-03 16:00:36 · 85 阅读 · 0 评论 -
vector<shared_ptr>与内存泄漏
#define _CRTDBG_MAP_ALLOC#include<crtdbg.h>#include<iostream>#include<vector>#include<memory>using namespace std;void f1() { vector<int*> vec; vec.push_back(new int(5)); vec.push_back(new int(6)); //cout << *.原创 2021-08-21 23:34:48 · 1911 阅读 · 0 评论 -
decltype、函数、函数指针、优先队列使用
#include<iostream>using namespace std;bool cmp(int a, int b) { return a > b;}int main() { decltype(cmp) t; decltype(&cmp) t1; bool t2; cout << typeid(t).name() << endl; //bool __cdecl(int,int) ...原创 2021-09-29 14:57:09 · 571 阅读 · 0 评论