Order of evaluation in C++ function parameters

后端 未结 6 864
野性不改
野性不改 2020-11-22 00:41

If we have three functions (foo, bar, and baz) that are composed like so...

foo(bar(), baz())

Is there any guarantee by the C++ standard th

6条回答
  •  孤独总比滥情好
    2020-11-22 01:14

    In C++11, the relevant text can be found in 8.3.6 Default arguments/9 (Emphasis mine)

    Default arguments are evaluated each time the function is called. The order of evaluation of function arguments is unspecified. Consequently, parameters of a function shall not be used in a default argument, even if they are not evaluated.

    The same verbiage is used by C++14 standard as well, and is found under the same section.

提交回复
热议问题