13.1
拷贝构造函数是一种特殊的构造函数,函数的名称必须和类名称一致,它必须的一个参数是本类型的一个引用变量
1. 对象以值传递的方式传入函数参数
2. 对象以值传递的方式从函数返回
3. 对象需要通过另外一个对象进行初始化
等
13.2
要使用引用
如果不是引用的话,拷贝构造函数将调用本身,将是无限循环
13.3
拷贝一个StrBlob会使shared_ptr计时器增1
拷贝一个StrBlobPtr并不会怎么样,weak_ptr 对shared_ptr没有影响
13.4
Point global;
Point foo_bar(Point arg) // 1
{
Point local = arg, *heap = new Point(global); // 2, 3
*heap = local;
Point pa[ 4 ] = { local, *heap }; // 4, 5
return *heap; // 6
}
13.5
#include <string>
class HasPtr {
public:
HasPtr(const std::string &s = std::string()) : ps(new std::string(s)), i(0) { }
HasPtr(const HasPtr& hp) : ps(new std::string(*hp.ps)), i(hp.i) { }
private:
std::string *ps;
int i;
};