Files
hustoj/web/cppreference-zh/chmhelp/cpp-memory-auto_ptr-operator_auto_ptr.html
2025-08-01 12:57:54 +08:00

60 lines
5.8 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::auto_ptr&lt;T&gt;::operator auto_ptr&lt;Y&gt;</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_memory_auto_ptr_operator_auto_ptr 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::auto_ptr&lt;T&gt;::</span>operator auto_ptr&lt;Y&gt;</h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-memory.html">memory</a>&lrm; | <a href="cpp-memory-auto_ptr.html">auto ptr</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-until-cxx17">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> Y <span class="sy1">&gt;</span><br />
operator auto_ptr_ref<span class="sy1">&lt;</span>Y<span class="sy1">&gt;</span><span class="br0">(</span><span class="br0">)</span> <span class="kw1">throw</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td>(1)</td>
<td><span class="t-mark">(C++11 &#20013;&#24323;&#29992;)</span><br />
<span class="t-mark-rev t-until-cxx17">(C++17 &#20013;&#31227;&#38500;)</span></td>
</tr>
<tr class="t-dcl t-until-cxx17">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> Y <span class="sy1">&gt;</span><br />
operator auto_ptr<span class="sy1">&lt;</span>Y<span class="sy1">&gt;</span><span class="br0">(</span><span class="br0">)</span> <span class="kw1">throw</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td>(2)</td>
<td><span class="t-mark">(C++11 &#20013;&#24323;&#29992;)</span><br />
<span class="t-mark-rev t-until-cxx17">(C++17 &#20013;&#31227;&#38500;)</span></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>&#36716;&#25442; <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> &#20026;&#23545;&#20110;&#30456;&#24322;&#31867;&#22411; <code>Y</code> &#30340; <code>auto_ptr</code> &#12290;</p>
<div class="t-li1"><span class="t-li">1)</span> &#36820;&#22238;&#20445;&#26377;&#21040; <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> &#24341;&#29992;&#30340;&#23454;&#29616;&#23450;&#20041;&#31867;&#22411;&#23545;&#35937;&#12290; <span class="t-lc"><a href="cpp-memory-auto_ptr.html">std::auto_ptr</a></span> <a href="cpp-memory-auto_ptr-auto_ptr.html">&#21487;&#36716;&#25442;</a>&#24182;&#19988;<a href="cpp-memory-auto_ptr-operator=.html">&#21487;&#36171;&#20540;</a>&#33258;&#27492;&#27169;&#26495;&#12290;&#20801;&#35768;&#23454;&#29616;&#20197;&#19981;&#21516;&#30340;&#21517;&#31216;&#25552;&#20379;&#35813;&#27169;&#26495;&#65292;&#25110;&#20197;&#20854;&#20182;&#26041;&#24335;&#23454;&#29616;&#31561;&#20215;&#30340;&#21151;&#33021;&#12290;</div>
<div class="t-li1"><span class="t-li">2)</span> &#20197;&#35843;&#29992; <span class="t-lc"><a href="cpp-memory-auto_ptr-release.html">release()</a></span> &#33719;&#24471;&#30340;&#25351;&#38024;&#26500;&#36896;&#26032;&#30340; <code>auto_ptr</code> &#12290;</div>
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">&#21442;&#25968;</span></h3>
<p>&#65288;&#26080;&#65289;</p>
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">&#36820;&#22238;&#20540;</span></h3>
<div class="t-li1"><span class="t-li">1)</span> &#20445;&#26377;&#21040; <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> &#30340;&#24341;&#29992;&#30340;&#23454;&#29616;&#23450;&#20041;&#31867;&#22411;&#23545;&#35937;&#12290;</div>
<div class="t-li1"><span class="t-li">2)</span> &#25317;&#26377;&#30001;&#35843;&#29992; <span class="t-lc"><a href="cpp-memory-auto_ptr-release.html">release()</a></span> &#33719;&#24471;&#30340;&#25351;&#38024;&#30340; <code>auto_ptr</code> &#12290;</div>
<h3><span class="mw-headline" id=".E6.B3.A8.E6.84.8F">&#27880;&#24847;</span></h3>
<p>&#28304;&#33258; <code>auto_ptr_ref</code> &#30340;&#26500;&#36896;&#20989;&#25968;&#21644;&#22797;&#21046;&#36171;&#20540;&#36816;&#31639;&#31526;&#20801;&#35768;&#20174;&#26080;&#21517;&#20020;&#26102;&#37327;&#22797;&#21046;&#26500;&#36896;&#21644;&#36171;&#20540; <span class="t-lc"><a href="cpp-memory-auto_ptr.html">std::auto_ptr</a></span> &#12290;&#22240;&#20026;&#20854;&#22797;&#21046;&#26500;&#36896;&#20989;&#25968;&#19982;&#22797;&#21046;&#36171;&#20540;&#36816;&#31639;&#31526;&#20197;&#38750; const &#24341;&#29992;&#25509;&#25910;&#21442;&#25968;&#65292;&#23427;&#20204;&#19981;&#33021;&#30452;&#25509;&#32465;&#23450;&#21491;&#20540;&#12290;&#28982;&#32780;&#33021;&#25191;&#34892;<strong class="selflink">&#29992;&#25143;&#23450;&#20041;&#36716;&#25442;</strong>&#65288;&#37322;&#25918;&#21407; <code>auto_ptr</code> &#65289;&#65292;&#20043;&#21518;&#20877;&#35843;&#29992;&#20197;&#20540;&#25509;&#25910; <code>auto_ptr_ref</code> &#30340;&#26500;&#36896;&#20989;&#25968;&#25110;&#22797;&#21046;&#36171;&#20540;&#36816;&#31639;&#31526;&#12290;&#36825;&#26159;<a href="cpp-utility-move.html">&#31227;&#21160;&#35821;&#20041;</a>&#30340;&#26089;&#26399;&#23454;&#29616;&#12290;</p>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>