When are temporaries created as part of a function call destroyed?

后端 未结 4 1100
-上瘾入骨i
-上瘾入骨i 2021-01-01 13:14

Is a temporary created as part of an argument to a function call guaranteed to stay around until the called function ends, even if the temporary isn\'t passed directly to th

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 13:36

    §12.2/3: "Temporary objects are destroyed as the last step in evaluating the full-expression (1.9) that (lexically) contains the point where they were created."

    IOW, you're safe -- the A object must not be destroyed until after foo returns.

提交回复
热议问题