cppreferences에 따르면 explicit runtime_error(const std::string& what_arg);
은 what_arg
의 콘텐츠를 복사하지 않습니다.std :: runtime_error의 ctor에 전달 된 문자열 객체의 수명은 어떻게됩니까?
안전하게 임시 문자열 개체를 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?
}
}
콘텐츠가 복사되지 않는다고하는 곳은 어디입니까? – immibis