cpp/error/system error/operator= — различия между версиями
Материал из cppreference.com
< cpp | error | system error
Olya (обсуждение | вклад) (Новая страница: «{{cpp/error/system_error/title|operator{{=}}}} {{cpp/error/system_error/navbar}} {{ddcl|since=c++11|1= system_error& operator=( const system_error& other ) noexce…») |
Olya (обсуждение | вклад) |
||
Строка 5: | Строка 5: | ||
}} | }} | ||
− | Присваивает содержимое из {{ | + | Присваивает содержимое из {{|other}}. Если {{|*this}} и {{|other}} имеют динамический тип {{tt|std::system_error}}, тогда {{c|1=std::strcmp(what(), other.what()) == 0}} после присваивания. |
===Параметры=== | ===Параметры=== | ||
Строка 16: | Строка 16: | ||
===Пример=== | ===Пример=== | ||
− | {{example}} | + | {{example |
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | }} | ||
{{langlinks|en|es|ja|zh}} | {{langlinks|en|es|ja|zh}} |
Текущая версия на 22:06, 27 августа 2023
system_error& operator=( const system_error& other ) noexcept; |
(начиная с C++11) | |
Присваивает содержимое из other. Если *this и other имеют динамический тип std::system_error
, тогда std::strcmp(what(), other.what()) == 0 после присваивания.
[править] Параметры
other | — | другой объект 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(), "Информация об ошибке #1"); print(e1); std::system_error e2(EIO, std::system_category(), "Информация об ошибке #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: [Информация об ошибке #1: Numerical argument out of domain] code: [system:5] message: [Input/output error] what: [Информация об ошибке #2: Input/output error] code: [system:5] message: [Input/output error] what: [Информация об ошибке #2: Input/output error]