Usage of string::c_str on temporary string [duplicate]

我们两清 提交于 2019-12-01 04:00:29

The temporary will be destroyed at the end of the expression, namely the ; semicolon. So you are safe.

§ 12.2 ... Temporary objects are destroyed as the last step in evaluating the full-expression (1.9) that (lexically) contains the point where they were created. This is true even if that evaluation ends in throwing an exception.

Is this ordering mandated by the standard or implementation-specific?

[class.temporary]/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.

so its mandated by the standard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!