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://www.zhihu.com/question/53520889
當然可以用移動構造函數來解決 向這樣
https://github.com/Mooophy/Cpp-Primer/issues/304#issuecomment-124081395
QueryResult(QueryResult &&) noexcept = default;新聞熱點
疑難解答