I have some code here that I am compiling with -Weffc++ -Wall -Wextra.
Basically I have this snippet:
class base
{};
class test : public base
{
public:
base& operator=(int)
{
return *this;
}
};
and I get the warning: warning: 'operator=' should return a reference to '*this' [-Weffc++]
. I am not really sure what to make of that warning. I have read that this is perfectly ok (i.e. to return a deferenced this).
Is there a way I can keep my complier happy?
Change your code to:
And everybody will be happy, not just your compiler.
PS: If you wish to know more the warnings produced by -Weffc++ are an extract of the recommendations found in this book :