0
Function argument evaluation order and constructor evaluation order
Hi We know that function argument evaluation order is not defined and not order is not guaranteed. Is it true for constructor also or it will be always right to left. In other words , refer code of decorator pattern as below: Query: is order of constructor call is fixed or not? https://sololearn.com/compiler-playground/cpBekkDpAv31/?ref=app
2 Answers
+ 2
Your example does not use multiple arguments. It uses nested parentheses so there is no ambiguity there. By definition (BODMAS/PEDMAS) the innermost parentheses are evaluated first, then outward. So your example is deterministic.
Multiple arguments means there is a list of arguments separated by commas. I haven't checked the C++ standards lately but it is safest to assume the ambiguity holds for method arguments, too. You'll write better code by not relying on order of argument evaluation.
Note: The comma that separates arguments is not the same as the comma operator. When the comma operator is used, then expressions are guaranteed to be evaluated left to right.
0
Thanks Brian