1

For clarification, I'm citing James McNellis answer in the post "Template assignment operator overloading mystery":

The implicitly-declared copy assignment operator, which is declared as follows, is still generated:

Wrapper& operator=(const Wrapper&);

Now I have a similar class and would like to know what the definition of this operator needs to look like.

Here's the class for recall:

template<typename T>
struct Wrapper;

What is now the correcting match:

template<typename T>
Wrapper& Wrapper<T>::operator=(const Wrapper&)

or

Wrapper& Wrapper::operator=(const Wrapper&)

?

Or is this just the same?

Community
  • 1
  • 1
Atmocreations
  • 9,923
  • 15
  • 67
  • 102

1 Answers1

2

This

template<typename T>
Wrapper& Wrapper<T>::operator=(const Wrapper&)

which is really just shorthand for

template<typename T>
Wrapper<T>& Wrapper<T>::operator=(const Wrapper<T>&)

The other version would apply to a non-template class named Wrapper, it has no effect on your templates.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720