yang131

导航

c++

c++ 11
std::ref 引用 头文件#include <functional>
std::cref const引用
std::move right ref
std::decay 类型转换
std::bind
std::bind1st
std::make_shared
std::tuple 多个值的pair集合
c++ 17
std::any
std::variant 代表的是一个结构体
std::optional 代表可为空

c++ 内存 模型
B 继承 A
构造: 先A 后B
析构: 先B 后A
e.g.
#include <string>
#include <iostream>

using namespace std;
class A
{
public:
A() { cout << "A constructor" << endl; }
virtual ~A() { cout << "A DeConstructor" << endl; }
};
class B : public A
{
public:
B() :A() { cout << "B constructor" << endl; }
~B() { cout << "B DeConstructor" << endl; }
};

int main(int argc, char** argv)
{
//必须使用多态的方式,析构函数是否为virtual 才会析构
A* a = new B();
delete a;
B b;

return 0;
}

环形引用:
shaderdptr,在最后一个加weakptr
weakptr:
sharedptr的实现:
void AddRef(){
ref* = new ref;
}
weakptr:
Aptr B
APtr C
tmp_ptr B和C互换

enable_shared_from_this:
在同一个类中需要传递shared_ptr时候需要继承,
这里boost库和stl都对此实现

posted on 2020-10-22 13:10  NoNight  阅读(84)  评论(0编辑  收藏  举报