I have an implementation of a template class Triple, which is a container holding any three types. My problem is that, my class takes three const references to values as parameter, and the values have to be private (definition), however, I also have to implement the copy-constructor and overloaded assignment operator.
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;
};
How would you implement the copy-constructor and assignment operator without assigning to const variables?