In a class template, I declare the copy constructor and implement it outside of the class in the following way:
template<typename T>
class MyClass
{
public:
MyClass(const MyClass<T> & other);
}
template<typename T>
MyClass<T>::MyClass(const MyClass<T> & other)
{
// Implementation
}
But I saw another kind of declaration and implementation, where there is no <T>
after MyClass in the parameter list:
template<typename T>
class MyClass
{
public:
MyClass(const MyClass & other);
}
template<typename T>
MyClass<T>::MyClass(const MyClass & other)
{
// Implementation
}
Which one is correct and what is the difference between these two kinds of declaration?
I try both in Visual Studio and both work. It makes me feel that they are equivalent but I am not sure about that.
1