Namespaces
Variants

std::system_error::operator=

Von de.cppreference.net
 
 
Hilfsmittelbibliothek
Sprachunterstützung
Typunterstützung (Basistypen, RTTI)
Bibliotheks-Feature-Test-Makros (C++20)
Programmhilfsmittel
Funktionen mit variabler Argumentanzahl
Koroutinenunterstützung (C++20)
Vertragsunterstützung (C++26)
Dreiseitiger Vergleich
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

Allgemeine Hilfsmittel
Vergleichsoperatoren (veraltet in C++20)
 
 
 
system_error& operator=( const system_error& other ) noexcept;
(seit C++11)

Weist die Inhalte von other zu. Wenn *this und other beide den dynamischen Typ std::system_error haben, dann ist std::strcmp(what(), other.what()) == 0 nach der Zuweisung.

Parameter

other - ein weiteres system_error Objekt zur Zuweisung

Rückgabewert

* this

Beispiel

#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);
}

Mögliche Ausgabe:

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]