名稱空間
變體
操作

std::bad_expected_access

來自 cppreference.com
< cpp‎ | 工具庫‎ | expected
 
 
 
 
定義於標頭檔案 <expected>
template< class E >
class bad_expected_access : public std::bad_expected_access<void>
(1) (C++23 起)
template<>
class bad_expected_access<void> : public std::exception
(2) (C++23 起)
1) 定義了一個物件型別,當訪問一個包含意外值的 `expected` 物件時,std::expected::value 會丟擲該型別的物件。`bad_expected_access` 儲存了意外值的一個副本。
2) `bad_expected_access` 是所有其他 `bad_expected_access` 特化類的基類。

目錄

[編輯] 主模板的成員

(建構函式)
構造一個 `bad_expected_access` 物件
(公開成員函式)
error
返回儲存的值
(公開成員函式)
what
返回解釋字串
(公開成員函式)

std::bad_expected_access::bad_expected_access

explicit bad_expected_access( E e );

構造一個新的 `bad_expected_access` 物件。用 `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;

返回解釋字串。

引數

(無)

返回值

指向以 null 結尾的字串的指標,包含解釋資訊。該字串適合轉換為 std::wstring 並顯示。指標保證至少在獲取它的異常物件被銷燬之前或對異常物件呼叫非 const 成員函式(例如,複製賦值運算子)之前有效。

注意

允許但不要求實現重寫 what()

[編輯] bad_expected_access<void> 特化版的成員

(建構函式)
構造一個 `bad_expected_access` 物件
(受保護成員函式)
(解構函式)
銷燬 `bad_expected_access` 物件
(受保護成員函式)
operator=
替換 `bad_expected_access` 物件
(受保護成員函式)
what
返回解釋字串
(公開成員函式)

`bad_expected_access` 的特殊成員函式是受保護的。它們只能由派生類呼叫。

[編輯] 示例