I have gone through some examples in the internet for operator overloading where the return type of operator+= is T&. Since we can't chain += like T a = b = c; is it okay to declare the return type as void. When using void everything seems to work correctly. Is there any situation we have to avoid it?
For ex:
class MyInteger{
private:
int x;
public:
MyInteger(const int& a):x(a){}
void operator+=(const MyInteger& rhs){
x += rhs.x;
}
};
MyInteger a(10);
a += a; //No need to return anything because we can't chain
a = a + (a += a);