when should i use '&' when overloading an operator?
You should use & on a type when ever you want that type to be a reference.
Typically, a reasonable rule of thumb is to do what the corresponding built-in operators do. If the corresponding built-in operator is a prvalue, then return an object in your overload, and if the built-in operator is an lvalue, then return an lvalue reference.
For example, 1+2 is a prvalue expression, so following the described advice, you should return an object when overloading the binary operator+.
A& operator+(const A& b)
{
A c;
c.val = this->val + b.val
return c;
}
This function returns a dangling reference. If the caller attempts to access the referred value, then the behaviour of the program will be undefined. Don't return a reference (nor pointer) to an automatic variable.