摘要:
移动构造函数 1. 移动构造函数示例: #include<iostream> #include<vector> #include<string> using namespace std; class Test { public: Test(const string& s = "hello world 阅读全文
摘要:
一、什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: int a = 100; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量。 下面看一个类对象拷贝的简单例子: 1 #include<iostream> 2 using n 阅读全文
摘要:
enable_shared_from_this 用法 enable_shared_from_this 是 C++ 标准库中的一个模板类,用于在类的成员函数内部安全地获取指向自身的 shared_ptr。为什么需要它?直接用 this 构造 shared_ptr 会导致双重释放: class Foo 阅读全文