Overloading the equals operator with a template using Effective C++

635 views Asked by At

I am porting old C++ code to an Effective C++ safe version. I read about problems with this flag, but as I don't have a choice wether to do it or not, it has to be. I came along a problem with overloading the equals operator when using a template.

I tried to move the functionality from header files to the actual cpp's, but this didn't have any effect. Removing the template worked, but as the template is needed, it just showed me where the problem is.

template <typename T1, typename T2>
MyClass& operator = ( const boost::tuple<T1,T2> & _v )
{
    //Some operations
    return *this;
}

Compiling this code throws the following error:

'operator=' should return a reference to *this

pointing at the exact line return *this;

MyClass does not inherit any other class. Is this a effc++ bug or is there anything I am missing?

0

There are 0 answers