xml*_*lmx 0 c++ standards exception object-lifetime c++11
根据cppreferences,explicit runtime_error( const std::string& what_arg );不会复制what_arg的内容.
我可以安全地将临时字符串对象传递给std::runtime_error's 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?
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |