I have the following code:
template<typename T> struct Pair3{ T first, second; Pair3() : first(T()), second(T()) {} Pair3(T first, T second) : first(first), second(second) {} Pair3(const Pair3<T>& in) : first(in.first), second(in.second) {} template<typename U> void copyFrom(Pair3<U> in); }; template<typename T> template<typename U> void Pair3<T>::copyFrom(Pair3<U> in){ first = in.first; second = in.second; } why do I have to write
template<typename T> template<typename U> before copyFrom implementation and I can't write:
template<typename T, typename U>. What would that mean? Why would that be wrong? Conversely: why can't I declare struct Pair3 like this:
template<typename T, typename U> struct Pair3{ T first, second; Pair3() : first(T()), second(T()) {} Pair3(T first, T second) : first(first), second(second) {} Pair3(const Pair3<T>& in) : first(in.first), second(in.second) {} void copyFrom(Pair3<U> in); }; or even:
template<typename T> template<typename U> struct Pair3{ T first, second; Pair3() : first(T()), second(T()) {} Pair3(T first, T second) : first(first), second(second) {} Pair3(const Pair3<T>& in) : first(in.first), second(in.second) {} void copyFrom(Pair3<U> in); }; Thanks!