テンプレートクラスTripleの実装があります。これは、任意の3つのタイプを保持するコンテナです。私の問題は、私のクラスがパラメーターとして値への3つのconst参照を取り、値がプライベート(定義)である必要があることですが、コピーコンストラクターとオーバーロードされた代入演算子も実装する必要があります。
template <typename T1, typename T2, typename T3>
class Triple
{
public:
Triple()
{ }
Triple(const T1 &a, const T2 &b, const T3 &c) : a(a), b(b), c(c)
{ }
// copy constructor
Triple(const Triple &triple) {
a = triple.first();
b = triple.second();
c = triple.third();
}
// assignment operator
Triple &operator=(const Triple& other) {
//Check for self-assignment
if (this == &other)
return *this;
a = other.first();
b = other.second();
c = other.third();
return *this;
}
private:
T1 const& a;
T2 const& b;
T3 const& c;
};
const変数に割り当てずに、コピーコンストラクターと代入演算子をどのように実装しますか?