+=

+

Do not do this!

MyClass& badFunc() {
    MyClass obj;
    return obj;  // ❌ 返回了局部变量引用!
}
 
int main() {
    MyClass& ref = badFunc(); // ⚠️ 悬垂引用
}

or

>> and <<

Cannot be a number function, but when we need to access private variable, we could use friend.

[]

General Rule of Thumb

=

  • Be used to do copy assignment, a special member function which is define by default.

  • Be used to do move assignment, another special member function which is define by default.

POLA: Principle of Least Astonishment

Design operators primarily to mimic conventional usage.

Something else