名前空間
変種
操作

std::system_error::operator=

From cppreference.com
< cpp‎ | error‎ | system error
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
 
 
system_error& operator=( const system_error& other ) noexcept;
(C++11以降)

other の内容を代入します。*thisother が両方とも動的型 std::system_error を持つ場合、代入後、std::strcmp(what(), other.what()) == 0 となります。

[編集] パラメータ

その他 - 代入する別の system_error オブジェクト

[編集] 戻り値

*this

[編集]

#include <cassert>
#include <cstring>
#include <iostream>
#include <system_error>
 
void print(const std::system_error& e)
{
    std::cout << "code:    [" << e.code() << "]\n"
                 "message: [" << e.code().message() << "]\n"
                 "what:    [" << e.what() << "]\n\n";
}
 
int main()
{
    std::system_error e1(EDOM, std::generic_category(), "Error info #1");
    print(e1);
 
    std::system_error e2(EIO, std::system_category(), "Error info #2");
    print(e2);
 
    e1 = e2;
    assert(std::strcmp(e1.what(), e2.what()) == 0);
    print(e1);
}

実行結果の例

code:    [generic:33]
message: [Numerical argument out of domain]
what:    [Error info #1: Numerical argument out of domain]
 
code:    [system:5]
message: [Input/output error]
what:    [Error info #2: Input/output error]
 
code:    [system:5]
message: [Input/output error]
what:    [Error info #2: Input/output error]
English 日本語 中文(简体) 中文(繁體)