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

后端 未结 4 1101
-上瘾入骨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:46

    The lifetime of your temp object A(4) will last long enough to call y()

    The memory pointed to in the return of y() is not reliable, depending on threading and allocations it may be reallocated and the value changed before the call to foo() makes use of it.

提交回复
热议问题