条項05:C++デフォルト作成呼び出し関数について
コンパイラはclassのdefaultコンストラクション関数、copyコンストラクション関数、copy assignmentオペレータ、およびコンストラクション関数を暗黙的に作成できます.
class Empty{};// Empty
class Empty
{
public:
Empty() {}; //default
Empty(const Empty& rsh) {}; //copy
~Empty() {}; //
Empty& operator=(const Empty& rhs) {}; //copy assignment
};
, copy assignment
template
class NameObject
{
public:
NameObject(string& name, const T& value) :
NameValue(name), objectName(value)
{
}
void operator=(const NameObject& rhs)
{
NameValue = rhs.NameValue;
objectName = rhs.objectName;
}
private:
string& NameValue;
const T objectName;
};
string newDog("Persephone");
string oldDog("Sactch");
NameObject<int> p(newDog, 2);
NameObject<int> s(oldDog, 2);
p = s;// C++ reference , objectValue const , &, '='