std::bad_optional_access
来自 zh.cppreference.net
| 在标头 <optional>
|
||
class bad_optional_access;
|
中定义 (C++17 起) | |
定义了一个对象类型,当访问不含值的 optional 对象时,由 std::optional::value 抛出。
继承图
成员函数
(构造函数) |
构造新的 bad_optional_access 对象 (公开成员函数) |
operator= |
替换 bad_optional_access 对象 (公开成员函数) |
what |
返回解释性字符串 (公开成员函数) |
std::bad_optional_access::bad_optional_access
bad_optional_access() noexcept;
|
(1) | (C++17 起) |
bad_optional_access( const bad_optional_access& other ) noexcept;
|
(2) | (C++17 起) |
构造新的 bad_optional_access 对象,带有实现定义的空终止字节字符串,可通过 what() 访问。
1) 默认构造函数。
2) 复制构造函数。若
*this 与 other 都具有动态类型 std::bad_optional_access,则 std::strcmp(what(), other.what()) == 0。参数
| other | - | 要复制的另一个异常对象 |
std::bad_optional_access::operator=
bad_optional_access& operator=( const bad_optional_access& other ) noexcept;
|
(C++17 起) | |
将内容赋值为 other 的内容。若 *this 与 other 都具有动态类型 std::bad_optional_access,则赋值后 std::strcmp(what(), other.what()) == 0。
参数
| other | - | 要用来赋值的另一个异常对象 |
返回值
*this
std::bad_optional_access::what
virtual const char* what() const noexcept;
|
(C++17 起) | |
返回解释性字符串。
返回值
指向实现定义的空终止字符串的指针,包含解释性信息。该字符串适合转换为 std::wstring 并显示。该指针保证在获取该指针的异常对象被销毁之前,或在异常对象的非 const 成员函数(例如复制赋值运算符)被调用之前有效。
|
在常量求值期间,返回的字符串使用普通字面量编码进行编码。 |
(C++26 起) |
注解
允许但并不要求实现覆盖 what()。
继承自 std::exception
成员函数
[虚函数] |
销毁异常对象 ( std::exception 的虚公开成员函数)
|
[虚函数] |
返回解释性字符串 ( std::exception 的虚公开成员函数)
|