Sunday, January 27, 2008

Overloading the && , || , " , " operators : C++

&& , || and comma operator in C++ are very useful . && and || are useful in short circuiting code .
Now when you overload these operator at the global level or at the member level . Then at that case

an expression like

(exp1 && exp2)

gets transformed into something like

(exp1.operator&&(exp2))

that being the case , both the arguments exp1 and exp2 are evaluated . Hence since we are not
sure in which order the arguments are evaluated , short circuiting is thrown out of the window.

So commonsense says it makes sense not to overload the && , || and the comma operator .

No comments: