【发布时间】:2016-12-12 01:44:28
【问题描述】:
根据cppreferences,explicit runtime_error( const std::string& what_arg );不会复制what_arg的内容。
我可以安全地将临时字符串对象传递到std::runtime_error 的ctor 吗?
例如:
std::string GetATempString(const char* msg)
{
return { msg };
}
int main()
{
try {
throw std::runtime_error(GetATempString("Hello"));
} catch (const std::runtime_error& e)
{
e.what(); // Is it guaranteed that "Hello" would be returned safely?
}
}
【问题讨论】:
-
哪里说内容没有被复制?
标签: c++ c++11 exception standards object-lifetime