【发布时间】:2016-07-13 13:21:45
【问题描述】:
给定以下类声明:
class phone_number
{
public:
explicit phone_number( std::string number ) noexcept( std::is_nothrow_move_constructible< std::string >::value );
}
phone_number::phone_number( std::string number ) noexcept( std::is_nothrow_move_constructible< std::string >::value )
: m_originalNumber{ std::move( number ) }
{
}
如果字符串构造函数抛出异常,以下代码行是否会由于 noexcept 规范而立即调用std::terminate()?
const phone_number phone("(123) 456-7890");
【问题讨论】:
-
const char *的字符串构造函数由 you 调用,而不是由phone_number构造函数调用。移动构造函数不会抛出。
标签: c++ c++11 exception noexcept