In operator overloading, the assignment operator is normally defined as follows:
T& T::operator =(const T2& b);
T& as result. But I want to know what happens when we return
void. For example, the assignment operator of
void operator=( std::shared_ptr<T> desired ) noexcept;
as defined here and here. What happens in this case? Is it ok to always implement the assignment operator like this? I guess this prevents assignments like
a=b=c; which is good sometimes, isn’t it?
You won’t be able to chain assignments
a = b = c;
(Nor introduce more complicated cases, like
(a = b).method(); or
if((a = b));.)
OTOH, with void return type you don’t need the ubiquitous
return *this; boilerplate.