In the following :
template<typename Derived>
class Base:
{
inline Derived& operator=(const Base<Derived>& x);
}
Does this declaration erases the default copy assignment operator or do I have two operators :
inline Derived& operator=(const Base<Derived>& x);
// (declared by me)
AND
inline Base<Derived>& operator=(const Base<Derived>& x);
// (declared by the compiler)
In this case, when I call the function, how the compiler will get the right operator ?
If you declare any method that can pass for an assignment operator:
XXX Foo::operator=(Foo&);
XXX Foo::operator=(Foo const&);
XXX Foo::operator=(Foo volatile&);
XXX Foo::operator=(Foo const volatile&);
then the compiler will not generate the default version Foo& operator=(Foo const&);.
Note that the return type is completely free, as for other methods. You could use void, bool, whatever really. It is just idiomatic (but not required) to return a reference to self in order to allow assignment chaining: a = b = c = 0; which itself stems from the guideline that overloaded operators should follow the semantics of their built-in counterparts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With