命名空间
变体
操作

std::experimental::bad_optional_access

来自 cppreference.cn
 
 
实验性
技术规范
Filesystem library (filesystem TS) (文件系统库)
Library fundamentals (library fundamentals TS) (库基础)
Library fundamentals 2 (library fundamentals TS v2) (库基础 2)
Library fundamentals 3 (library fundamentals TS v3) (库基础 3)
Extensions for parallelism (parallelism TS) (并行扩展)
Extensions for parallelism 2 (parallelism TS v2) (并行扩展 2)
Extensions for concurrency (concurrency TS) (并发扩展)
Extensions for concurrency 2 (concurrency TS v2) (并发扩展 2)
Concepts (concepts TS) (概念)
Ranges (ranges TS) (范围)
Reflection (reflection TS) (反射)
Mathematical special functions (special functions TR) (数学特殊函数)
实验性非TS
模式匹配
线性代数
std::execution
契约
2D图形
 
 
 
定义于头文件 <experimental/optional>
class bad_optional_access;
(library fundamentals TS)

定义了当访问不包含值的 optional 对象时,由 std::experimental::optional::value 抛出的对象类型。

cpp/error/exceptioncpp/error/logic errorstd-bad optional access-inheritance.svg

继承关系图

目录

[edit] 成员函数

(构造函数)
构造一个新的 bad_optional_access 对象
(公共成员函数)
operator=
替换 bad_optional_access 对象
(公共成员函数)
what
返回解释性字符串
(公共成员函数)

std::experimental::bad_optional_access::bad_optional_access

bad_optional_access() noexcept;
(1) (library fundamentals TS)
bad_optional_access( const bad_optional_access& other ) noexcept;
(2) (library fundamentals TS)

构造一个新的 bad_optional_access 对象,其中包含一个实现定义的空终止字节字符串,可以通过 what() 访问。

1) 默认构造函数。
2) 复制构造函数。如果 *thisother 都具有动态类型 std::experimental::bad_optional_access,则 std::strcmp(what(), other.what()) == 0

参数

other - 要复制的另一个异常对象

std::experimental::bad_optional_access::operator=

bad_optional_access& operator=( const bad_optional_access& other ) noexcept;
(library fundamentals TS)

将内容赋值为 other 的内容。如果 *thisother 都具有动态类型 std::experimental::bad_optional_access,则赋值后 std::strcmp(what(), other.what()) == 0

参数

other - 要赋值的另一个异常对象

返回值

*this

std::experimental::bad_optional_access::what

virtual const char* what() const noexcept;
(library fundamentals TS)

返回解释性字符串。

返回值

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

返回的字符串在常量求值期间使用普通的字面编码进行编码。

(自 C++26 起)

注释

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

继承自 std::logic_error

继承自 std::exception

成员函数

[虚函数]
销毁异常对象
(std::exception 的虚公共成员函数) [编辑]
[虚函数]
返回解释性字符串
(std::exception 的虚公共成员函数) [编辑]