67 lines
4.5 KiB
HTML
67 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
|
|
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>std::error_code::operator=</title>
|
|
<link rel="stylesheet" href="ext.css" />
|
|
<link rel="stylesheet" href="site_modules.css" />
|
|
</head>
|
|
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_error_error_code_operator skin-cppreference2 action-view cpp-navbar">
|
|
<div id="cpp-content-base">
|
|
<div id="content"><a id="top"></a>
|
|
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::error_code::</span>operator=</h1>
|
|
<div id="bodyContent">
|
|
<div id="contentSub"><span class="subpages">< <a href="cpp.html">cpp</a>‎ | <a href="cpp-error.html">error</a>‎ | <a href="cpp-error-error_code.html">error code</a></span></div>
|
|
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
|
|
<table class="t-dcl-begin">
|
|
<tbody>
|
|
<tr class="t-dcl t-since-cxx11">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1"><</span> <span class="kw1">class</span> ErrorCodeEnum <span class="sy1">></span><br />
|
|
error_code<span class="sy3">&</span> operator<span class="sy1">=</span><span class="br0">(</span> ErrorCodeEnum e <span class="br0">)</span> <span class="kw1">noexcept</span><span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td class="t-dcl-nopad"></td>
|
|
<td><span class="t-mark-rev t-since-cxx11">(C++11 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl-sep">
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>以表示错误码枚举 <code>e</code> 者替换错误码和对应类别。</p>
|
|
<p>等价于 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this <span class="sy1">=</span> make_error_code<span class="br0">(</span>e<span class="br0">)</span></span></span> ,其中以无限定调用 <code>make_error_code</code> 以启用<a href="cpp-language-adl.html">实参依赖查找</a>。此重载仅若 <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="cpp-error-error_code-is_error_code_enum.html"><span class="kw878">std::<span class="me2">is_error_code_enum</span></span></a><span class="sy1"><</span>ErrorCodeEnum<span class="sy1">></span><span class="sy4">::</span><span class="me2">value</span></span></span> 为 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw2">true</span></span></span> 才参与重载决议。</p>
|
|
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">参数</span></h3>
|
|
<table class="t-par-begin">
|
|
<tr class="t-par">
|
|
<td>e</td>
|
|
<td>-</td>
|
|
<td>要构造的错误码枚举</td>
|
|
</tr>
|
|
</table>
|
|
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">返回值</span></h3>
|
|
<p><span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span></p>
|
|
<h3><span class="mw-headline" id=".E6.B3.A8.E8.A7.A3">注解</span></h3>
|
|
<p>复制赋值运算符为隐式定义。</p>
|
|
<p>最初的提案 <a rel="nofollow" class="external text" href="https://wg21.link/N2422">N2422</a> 中有意使用 ADL 所找到的 <code>make_error_code</code> ,并且已知实现均使用它。然而,标准要求只考虑 <code>std::make_error_code</code> 重载。此为 <a rel="nofollow" class="external text" href="https://cplusplus.github.io/LWG/issue3629">LWG 问题 3629</a> 。</p>
|
|
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>
|
|
<table class="t-dsc-begin">
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-error-error_code-assign.html"><span class="t-lines"><span>assign</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>赋值为另一 error_code<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|