Overloading logical operators considered bad practice?

前端 未结 7 725
星月不相逢
星月不相逢 2021-01-11 13:40

Is it a bad idea to overload &&, || or comma operator and Why?

7条回答
  •  萌比男神i
    2021-01-11 14:16

    I'd say it depends on what your overloads are doing. For example, && and || are expected to work as logical conditions, so if your overload semantics work somehow differently, they can confuse other people (or even yourself, if you don't use them for a while and forget what they do). Consider what you would expect the operators to do if you wouldn't know how they are overloaded and if it would be clearer to just use normal methods instead.

提交回复
热议问题