13.18
#include<string>
using std::string;
class Employee {
Employee(const string& aname):name(aname){
id = increment++;
}
Employee() {
id = increment++;
}
private:
string name;
int id;
static int increment ;
};
13.19
不需要,每个员工都是独一无二的,不能拷贝
#include<string>
using std::string;
class Employee {
Employee(const string& aname):name(aname){
id = increment++;
}
Employee() {
id = increment++;
}
Employee(const Employee&) = delete;
Employee& operator=(const Employee&) = delete;
private:
string name;
int id;
static int increment ;
};
13.20
智能指针计时器会发生变化,对象可能会被创建和销毁,但是指针指的内存取决于计时器的变化
13.21
我认为需要,因为没有,有些操作会出错
比如:
当然可以用移动构造函数来解决
向这样
https://github.com/Mooophy/Cpp-Primer/issues/304#issuecomment-124081395
QueryResult(QueryResult &&) noexcept = default;