命名空间
变体
操作

std::bad_expected_access

来自 cppreference.cn
< cpp‎ | utility‎ | expected
 
 
 
 
定义于头文件 <expected>
template< class E >
class bad_expected_access : public std::bad_expected_access<void>
(1) (since C++23)
template<>
class bad_expected_access<void> : public std::exception
(2) (since C++23)
1) 定义了当访问包含非预期值的 expected 对象时,由 std::expected::value 抛出的对象类型。 bad_expected_access<E> 存储了非预期值的副本。
2) bad_expected_access<void> 是所有其他 bad_expected_access 特化版本的基类。

目录

[编辑] 主模板的成员

(构造函数)
构造一个 bad_expected_access 对象
(公共成员函数)
error
返回存储的值
(公共成员函数)
what
返回解释性字符串
(公共成员函数)

std::bad_expected_access::bad_expected_access

explicit bad_expected_access( E e );

构造一个新的 bad_expected_access<E> 对象。 使用 std::move(e) 初始化存储的值。

std::bad_expected_access::error

const E& error() const & noexcept;

E& error() & noexcept;
const E&& error() const && noexcept;

E&& error() && noexcept;

返回对存储值的引用。

std::bad_expected_access::what

const char* what() const noexcept override;

返回解释性字符串。

参数

(无)

返回值

指向包含解释性信息的空终止字符串的指针。该字符串适合转换为 std::wstring 并显示。指针保证有效,至少到获取它的异常对象被销毁为止,或者直到调用异常对象上的非 const 成员函数(例如,复制赋值运算符)为止。

注解

允许但不是必须实现 what() 的重写。

[编辑] bad_expected_access<void> 特化版本的成员

(构造函数)
构造一个 bad_expected_access<void> 对象
(受保护的成员函数)
(析构函数)
销毁 bad_expected_access<void> 对象
(受保护的成员函数)
operator=
替换 bad_expected_access<void> 对象
(受保护的成员函数)
what
返回解释性字符串
(公共成员函数)

bad_expected_access<void> 的特殊成员函数是受保护的。 它们只能由派生类调用。

[编辑] 示例