{"id":32596,"date":"2025-04-24T20:18:01","date_gmt":"2025-04-24T12:18:01","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/32596.html"},"modified":"2025-04-24T20:18:01","modified_gmt":"2025-04-24T12:18:01","slug":"c-%e4%ba%92%e6%96%a5%e9%94%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/32596.html","title":{"rendered":"c++ \u4e92\u65a5\u9501"},"content":{"rendered":"<p>\u4e3a\u7ec3\u4e60c&#043;&#043; \u7ebf\u7a0b\u540c\u6b65&#xff0c;\u505a\u4e86LeeCode 1114\u9898. \u6309\u5e8f\u6253\u5370&#xff1a;<\/p>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u7c7b&#xff1a;<\/p>\n<p>public class Foo {<br \/>\n\u00a0 public void first() { print(&#034;first&#034;); }<br \/>\n\u00a0 public void second() { print(&#034;second&#034;); }<br \/>\n\u00a0 public void third() { print(&#034;third&#034;); }<br \/>\n} <\/p>\n<p>\u4e09\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b A\u3001B\u3001C \u5c06\u4f1a\u5171\u7528\u4e00\u4e2a\u00a0Foo\u00a0\u5b9e\u4f8b\u3002<\/p>\n<ul>\n<li>\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528\u00a0first()\u00a0\u65b9\u6cd5<\/li>\n<li>\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528\u00a0second()\u00a0\u65b9\u6cd5<\/li>\n<li>\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528\u00a0third()\u00a0\u65b9\u6cd5<\/li>\n<\/ul>\n<p>\u8bf7\u8bbe\u8ba1\u4fee\u6539\u7a0b\u5e8f&#xff0c;\u4ee5\u786e\u4fdd\u00a0second()\u00a0\u65b9\u6cd5\u5728\u00a0first()\u00a0\u65b9\u6cd5\u4e4b\u540e\u88ab\u6267\u884c&#xff0c;third()\u00a0\u65b9\u6cd5\u5728\u00a0second()\u00a0\u65b9\u6cd5\u4e4b\u540e\u88ab\u6267\u884c\u3002<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\u5c3d\u7ba1\u8f93\u5165\u4e2d\u7684\u6570\u5b57\u4f3c\u4e4e\u6697\u793a\u4e86\u987a\u5e8f&#xff0c;\u4f46\u662f\u6211\u4eec\u5e76\u4e0d\u4fdd\u8bc1\u7ebf\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u8c03\u5ea6\u987a\u5e8f\u3002<\/li>\n<li>\u4f60\u770b\u5230\u7684\u8f93\u5165\u683c\u5f0f\u4e3b\u8981\u662f\u4e3a\u4e86\u786e\u4fdd\u6d4b\u8bd5\u7684\u5168\u9762\u6027\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;nums &#061; [1,2,3]<br \/>\n\u8f93\u51fa&#xff1a;&#034;firstsecondthird&#034;<br \/>\n\u89e3\u91ca&#xff1a;<br \/>\n\u6709\u4e09\u4e2a\u7ebf\u7a0b\u4f1a\u88ab\u5f02\u6b65\u542f\u52a8\u3002\u8f93\u5165 [1,2,3] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5&#xff0c;\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5&#xff0c;\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\u3002\u6b63\u786e\u7684\u8f93\u51fa\u662f &#034;firstsecondthird&#034;\u3002<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;nums &#061; [1,3,2]<br \/>\n\u8f93\u51fa&#xff1a;&#034;firstsecondthird&#034;<br \/>\n\u89e3\u91ca&#xff1a;<br \/>\n\u8f93\u5165 [1,3,2] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5&#xff0c;\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5&#xff0c;\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\u3002\u6b63\u786e\u7684\u8f93\u51fa\u662f &#034;firstsecondthird&#034;\u3002 <\/p>\n<ul><\/ul>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>nums\u00a0\u662f\u00a0[1, 2, 3]\u00a0\u7684\u4e00\u7ec4\u6392\u5217<\/li>\n<\/ul>\n<p>\u7b54\u6848&amp;\u6d4b\u8bd5\u4ee3\u7801&#xff1a;<\/p>\n<p>\u00a0<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &#034;listNode.h&#034;<br \/>\n#include &#034;solution.h&#034;<br \/>\n#include &lt;algorithm&gt;<br \/>\n#include &lt;unordered_set&gt;<br \/>\n#include &lt;unordered_map&gt;<br \/>\n#include &lt;map&gt;<br \/>\n#include &lt;string&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &#034;solution3.h&#034;<br \/>\n#include &#034;dataDefine.h&#034;<br \/>\n#include &#034;uthash.h&#034;<br \/>\n#include &#034;IntArrayList.h&#034;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;thread&gt;<br \/>\n#include &lt;atomic&gt;<br \/>\n#include &#034;DemoClass.h&#034;<br \/>\n#include &lt;mutex&gt;<br \/>\n#include &lt;condition_variable&gt;<br \/>\n#include &lt;functional&gt;<\/p>\n<p>void printFirst() {<br \/>\nstd::cout &lt;&lt; &#034;first&#034;;<br \/>\n}<\/p>\n<p>void printSecond() {<br \/>\nstd::cout &lt;&lt; &#034;second&#034;;<br \/>\n}<\/p>\n<p>void printThird() {<br \/>\nstd::cout &lt;&lt; &#034;third&#034;;<br \/>\n}<\/p>\n<p>void testLeeCode1114_() {<br \/>\nclass Foo { \/\/ \u51fd\u6570\u5185\u90e8\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u7c7b\u3002<br \/>\nprivate:<br \/>\nstd::mutex mtx; \/\/ \u4e92\u65a5\u9501<br \/>\nstd::condition_variable cv; \/\/ \u6761\u4ef6\u53d8\u91cf<br \/>\nbool isFirstDone;<br \/>\nbool isSecondDone;<br \/>\npublic:<br \/>\nFoo() {<br \/>\nthis-&gt;isFirstDone &#061; false;<br \/>\nthis-&gt;isSecondDone &#061; false;<br \/>\n}<\/p>\n<p>void first(function&lt;void()&gt; printFirst) {<br \/>\n{ \/\/ \u52a0\u4e00\u5bf9{}\u662f\u4e3a\u4e86\u9650\u5236\u4e0b\u9762\u52a0\u9501\u7684\u4f5c\u7528\u57df\u3002\u79bb\u5f00\u4f5c\u7528\u57dflock_guard\u81ea\u52a8\u7acb\u5373\u91ca\u653e\u9501<br \/>\n\/\/ lock_guard\u6784\u9020\u65f6\u7acb\u5373\u52a0\u9501&#xff08;\u5982\u679c\u9501\u88ab\u5360\u7528\u4f1a\u7b49\u5f85\u9501\u91ca\u653e&#xff0c;\u4e00\u65e6\u9501\u91ca\u653e\u5c31\u62a2\u5360&#xff09;\u3002\u4e0d\u652f\u6301\u624b\u52a8\u91ca\u653e\u9501\u3002lock_guard \u5728\u6790\u6784\u65f6\u4f1a\u81ea\u52a8\u91ca\u653e\u9501\u3002<br \/>\nstd::lock_guard&lt;std::mutex&gt; lock(mtx);<br \/>\n\/\/ printFirst() outputs &#034;first&#034;. Do not change or remove this line.<br \/>\nprintFirst();<br \/>\nthis-&gt;isFirstDone &#061; true;<br \/>\n}<br \/>\ncv.notify_all(); \/\/ \u5524\u9192\u6240\u6709\u7b49\u5f85\u9501\u7684\u7ebf\u7a0b<br \/>\n}<\/p>\n<p>void second(function&lt;void()&gt; printSecond) {<br \/>\n\/\/ \u7acb\u5373\u52a0\u9501&#xff0c;\u540clock_guard&#xff0c; \u4f46\u662funique_lock\u6bd4\u8f83\u7075\u6d3b&#xff0c;\u8fd8\u652f\u6301\u5ef6\u8fdf\u52a0\u9501\u3002\u652f\u6301\u624b\u52a8\u52a0\u9501\u3001\u91ca\u653e\u9501\u3002\u9700\u8981\u624b\u52a8\u7ba1\u7406\u3002<br \/>\nstd::unique_lock&lt;std::mutex&gt; lock(mtx);<\/p>\n<p>\/\/ \u5224\u65ad\u662f\u5426\u6ee1\u8db3\u6267\u884c\u6761\u4ef6\u3002\u5982\u679c\u4e0d\u6ee1\u8db3\u5c31\u8c03\u7528wait\u51fd\u6570\u91ca\u653e\u9501&#xff0c;\u8be5\u7ebf\u7a0b\u963b\u585e\u5728\u8fd9\u91cc\u7b49\u5f85\u88ab\u5524\u9192&#xff1b; \u82e5\u6ee1\u8db3\u6267\u884c\u6761\u4ef6\u5219\u7ee7\u7eed\u4e0b\u9762\u7684\u4ee3\u7801\u903b\u8f91\u3002<br \/>\n\/\/ \u88ab\u5524\u9192\u4f1a\u5224\u65ad\u662f\u5426\u6ee1\u8db3\u6267\u884c\u6761\u4ef6&#xff0c;\u4e14\u6ee1\u8db3\u6761\u4ef6\u5219\u83b7\u53d6\u9501&#xff0c;\u7136\u540e\u7ee7\u7eed\u4e0b\u9762\u7684\u4ee3\u7801\u903b\u8f91\u3002\u4e0d\u6ee1\u8db3\u6761\u4ef6\u5219\u7ee7\u7eed\u7b49\u5f85\u3002<br \/>\ncv.wait(lock, [this](){return this-&gt;isFirstDone;}); \/\/ \u8fd9\u91cc\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2alambda\u8868\u8fbe\u5f0f&#xff0c;\u8868\u793a\u4e00\u4e2a\u533f\u540d\u51fd\u6570&#xff0c;\u8be5\u51fd\u6570\u6355\u83b7this\u6307\u9488&#xff08;\u51fd\u6570\u4f53\u4e2d\u7528\u5230\u8be5\u6307\u9488&#xff09;&#xff0c;\u6ca1\u6709\u53c2\u6570\u3002<\/p>\n<p>\/\/ printSecond() outputs &#034;second&#034;. Do not change or remove this line.<br \/>\nprintSecond();<\/p>\n<p>this-&gt;isSecondDone &#061; true;<\/p>\n<p>lock.unlock(); \/\/ \u4e0d\u8981\u5fd8\u8bb0\u91ca\u653e\u9501\u3002\u56e0\u4e3a\u7ebf\u7a0b\u88ab\u5524\u9192\u540e\u9700\u8981\u83b7\u53d6\u9501\u8d44\u6e90\u624d\u4f1a\u6267\u884c\u5230\u8fd9\u91cc&#xff0c;\u6240\u4ee5\u5fc5\u987b\u518d\u91ca\u653e&#xff0c;\u4e0d\u80fd\u56e0\u4e3a\u4e0a\u9762wait\u51fd\u6570\u91ca\u653e\u9501\u4e86\u5c31\u4e0d\u8c03\u7528\u91ca\u653e\u4e86\u3002<\/p>\n<p>cv.notify_all(); \/\/ \u9700\u8981\u901a\u77e5\u5176\u4ed6\u7ebf\u7a0b, \u8fd9\u91cc\u4e5f\u53ef\u4ee5\u8c03\u7528notify_one&#xff0c; \u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u5728\u7b49\u5f85\u4e86\u3002<br \/>\n}<\/p>\n<p>void third(function&lt;void()&gt; printThird) {<br \/>\nstd::unique_lock&lt;std::mutex&gt; lock(mtx);<br \/>\ncv.wait(lock, [this]() {return this-&gt;isSecondDone;});<br \/>\n\/\/ printThird() outputs &#034;third&#034;. Do not change or remove this line.<br \/>\nprintThird();<br \/>\nlock.unlock();<br \/>\n}<br \/>\n};<\/p>\n<p>Foo foo; \/\/ \u4e3b\u7ebf\u7a0b\u751f\u6210Foo\u5bf9\u8c61\u3002<br \/>\n    \/\/ \u56e0\u4e3a\u7ebf\u7a0b\u8981\u6267\u884c\u5bf9\u8c61\u91cc\u7684\u6210\u5458\u51fd\u6570&#xff0c;\u6240\u4ee5\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u51fd\u6570\u6307\u9488&#xff0c; \u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u8be5\u5bf9\u8c61&#xff0c;\u540e\u9762\u7684\u53c2\u6570\u662f\u8be5\u6210\u5458\u51fd\u6570\u7684\u4f20\u53c2&#xff0c;\u8fd9\u91cc\u4f20\u9012\u7684\u51fd\u6570<br \/>\nstd::thread t1(&amp;Foo::first, &amp;foo, printFirst);<br \/>\nstd::thread t3(&amp;Foo::third, &amp;foo, printThird);<br \/>\nstd::thread t2(&amp;Foo::second, &amp;foo, printSecond);<\/p>\n<p>t1.join();<br \/>\nt2.join();<br \/>\nt3.join();<br \/>\nstd::cout &lt;&lt; endl &lt;&lt; &#034;finish&#034; &lt;&lt; endl;<br \/>\n} <\/p>\n<p>\u6267\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"419\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250424121800-680a2bf81b803.png\" width=\"1222\" \/><\/p>\n<p>ok&#xff01;<\/p>\n<p>\u63d0\u4ea4\u5230LeeCode&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"672\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250424121800-680a2bf86414f.png\" width=\"741\" \/><\/p>\n<p>ok&#xff01; \u6ca1\u95ee\u9898\u3002<\/p>\n<\/p>\n<p>\u53cd\u9762\u6559\u6750&#xff1a;<\/p>\n<p>void testLeeCode1114() { \/\/ LeeCode1114.\u6309\u5e8f\u6253\u5370. \u53cd\u9762\u6559\u6750&#xff0c;\u4e3b\u7ebf\u7a0b\u52a0\u9501&#xff0c;\u5b50\u7ebf\u7a0b\u89e3\u9501&#xff0c;\u62a5\u9519&#xff1a;unlock of unowned mutex \u3002<br \/>\nclass Foo {<br \/>\nmutex mtx_1, mtx_2;<br \/>\nunique_lock&lt;mutex&gt; lock_1, lock_2;<br \/>\npublic:<br \/>\nFoo() : lock_1(mtx_1, try_to_lock), lock_2(mtx_2, try_to_lock) {<br \/>\n}<\/p>\n<p>void first(function&lt;void()&gt; printFirst) {<br \/>\nprintFirst();<br \/>\nlock_1.unlock();<br \/>\n}<\/p>\n<p>void second(function&lt;void()&gt; printSecond) {<br \/>\nlock_guard&lt;mutex&gt; guard(mtx_1);<br \/>\nprintSecond();<br \/>\nlock_2.unlock();<br \/>\n}<\/p>\n<p>void third(function&lt;void()&gt; printThird) {<br \/>\nlock_guard&lt;mutex&gt; guard(mtx_2);<br \/>\nprintThird();<br \/>\n}<br \/>\n};<\/p>\n<p>Foo foo; \/\/ \u4e3b\u7ebf\u7a0b\u751f\u6210Foo\u5bf9\u8c61\u3002<br \/>\nstd::thread t1(&amp;Foo::first, &amp;foo, printFirst); \/\/ \u56e0\u4e3a\u662f\u7ebf\u7a0b\u8981\u6267\u884c\u5bf9\u8c61\u91cc\u7684\u6210\u5458\u51fd\u6570&#xff0c;\u6240\u4ee5\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u51fd\u6570\u6307\u9488&#xff0c; \u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u8be5\u5bf9\u8c61&#xff0c;\u540e\u9762\u7684\u53c2\u6570\u662f\u8be5\u6210\u5458\u51fd\u6570\u7684\u4f20\u53c2&#xff0c;\u8fd9\u91cc\u4f20\u9012\u7684\u51fd\u6570<br \/>\nstd::thread t3(&amp;Foo::third, &amp;foo, printThird);<br \/>\nstd::thread t2(&amp;Foo::second, &amp;foo, printSecond);<\/p>\n<p>\/\/ \u4e3b\u7ebf\u7a0b\u7b49\u8fd93\u4e2a\u7ebf\u7a0b\u6267\u884c\u7ed3\u675f&#xff1a;<br \/>\nt1.join();<br \/>\nt2.join();<br \/>\nt3.join();<\/p>\n<p>\/\/ \u62a5\u9519&#xff1a; unlock of unowned mutex<br \/>\n} <\/p>\n<p>\u00a0\u62a5\u9519&#xff1a;unlock of unowned mutex \u3002\u00a0<\/p>\n<p>\u95ee\u9898\u5c31\u5728\u4e8e\u4e3b\u7ebf\u7a0b\u52a0\u9501&#xff0c; \u7136\u540e\u5b50\u7ebf\u7a0b\u89e3\u9501\u3002\u6240\u4ee5\u62a5\u9519\u3002\u7ebf\u7a0b\u5fc5\u987b\u5148\u5360\u6709\u9501\u8d44\u6e90\u624d\u80fd\u89e3\u9501\u3002<\/p>\n<\/p>\n<p>\u603b\u7ed3&#xff1a; \u4e92\u65a5\u9501\u5c31\u7c7b\u6bd4\u4e00\u4e2a\u5355\u4eba\u7528\u7684\u536b\u751f\u95f4\u3002\u4e00\u4e2a\u4eba&#xff08;\u7ebf\u7a0b&#xff09;\u8fdb\u53bb\u4e86\u4f1a\u628a\u536b\u751f\u95f4\u9501\u4f4f&#xff08;\u52a0\u9501&#xff09;&#xff0c; \u6b64\u65f6\u5176\u4ed6\u4eba&#xff08;\u7ebf\u7a0b&#xff09;\u60f3\u8fdb\u53bb\u53ea\u80fd\u7b49\u5f85\u9501\u91ca\u653e\u3002<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u540e\u53d1\u73b0\u4e0d\u6ee1\u8db3\u529e\u4e8b\u6761\u4ef6&#xff0c;\u6bd4\u5982\u6ca1\u5e26\u7eb8&#xff08;\u5982\u793a\u4f8b\u4ee3\u7801\u4e2d\u5224\u65ad\u4e0d\u6ee1\u8db3\u6267\u884c\u6761\u4ef6&#xff09;&#xff0c;\u6b64\u65f6\u51fa\u53bb\u7b49\u5f85&#xff08;\u5982\u793a\u4f8b\u4ee3\u7801\u7684wait\u51fd\u6570\u91ca\u653e\u9501&#xff09;&#xff0c;\u522b\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u5b8c\u4e8b\u540e\u51fa\u6765\u901a\u77e5\u8bf4\u4ed6\u7528\u5b8c\u4e86&#xff0c;\u7136\u540e\u521a\u624d\u51fa\u53bb\u7b49\u5f85\u7684\u90a3\u4e2a\u4eba\u518d\u6b21\u7ade\u4e89\u5230\u536b\u751f\u95f4\u8fdb\u53bb\u4e86&#xff0c; \u7136\u540e\u4f1a\u518d\u6b21\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3&#xff08;\u5982\u4ee3\u7801\u4e2d\u7684\u6761\u4ef6\u5224\u65ad&#xff09;&#xff0c;\u53d1\u73b0\u536b\u751f\u95f4\u6709\u7eb8\u4e86&#xff0c;ok\u53ef\u4ee5\u65b9\u4fbf\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb338\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf5\u6b21\u3002\u5982\u679c\u4e00\u4e2a\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u540e\u53d1\u73b0\u4e0d\u6ee1\u8db3\u529e\u4e8b\u6761\u4ef6\uff0c\u6bd4\u5982\u6ca1\u5e26\u7eb8\uff08\u5982\u793a\u4f8b\u4ee3\u7801\u4e2d\u5224\u65ad\u4e0d\u6ee1\u8db3\u6267\u884c\u6761\u4ef6\uff09\uff0c\u6b64\u65f6\u51fa\u53bb\u7b49\u5f85\uff08\u5982\u793a\u4f8b\u4ee3\u7801\u7684wait\u51fd\u6570\u91ca\u653e\u9501\uff09\uff0c\u522b\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u5b8c\u4e8b\u540e\u51fa\u6765\u901a\u77e5\u8bf4\u4ed6\u7528\u5b8c\u4e86\uff0c\u7136\u540e\u521a\u624d\u51fa\u53bb\u7b49\u5f85\u7684\u90a3\u4e2a\u4eba\u518d\u6b21\u7ade\u4e89\u5230\u536b\u751f\u95f4\u8fdb\u53bb\u4e86\uff0c \u7136\u540e\u4f1a\u518d\u6b21\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\uff08\u5982\u4ee3\u7801\u4e2d\u7684\u6761\u4ef6\u5224\u65ad\uff09\uff0c\u53d1\u73b0\u536b\u751f\u95f4\u6709\u7eb8\u4e86\uff0cok\u53ef\u4ee5\u65b9\u4fbf\u4e86\u3002\u8f93\u5165 [1,2,3] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5\uff0c\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\uff0c\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\u3002\u603b\u7ed3\uff1a \u4e92\u65a5\u9501\u5c31\u7c7b\u6bd4\u4e00\u4e2a\u5355\u4eba\u7528\u7684\u536b\u751f\u95f4\u3002<\/p>\n","protected":false},"author":2,"featured_media":32594,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1054,55,2651,427],"topic":[],"class_list":["post-32596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c-c","tag-c","tag-leecode","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>c++ \u4e92\u65a5\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/32596.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"c++ \u4e92\u65a5\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb338\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf5\u6b21\u3002\u5982\u679c\u4e00\u4e2a\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u540e\u53d1\u73b0\u4e0d\u6ee1\u8db3\u529e\u4e8b\u6761\u4ef6\uff0c\u6bd4\u5982\u6ca1\u5e26\u7eb8\uff08\u5982\u793a\u4f8b\u4ee3\u7801\u4e2d\u5224\u65ad\u4e0d\u6ee1\u8db3\u6267\u884c\u6761\u4ef6\uff09\uff0c\u6b64\u65f6\u51fa\u53bb\u7b49\u5f85\uff08\u5982\u793a\u4f8b\u4ee3\u7801\u7684wait\u51fd\u6570\u91ca\u653e\u9501\uff09\uff0c\u522b\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u5b8c\u4e8b\u540e\u51fa\u6765\u901a\u77e5\u8bf4\u4ed6\u7528\u5b8c\u4e86\uff0c\u7136\u540e\u521a\u624d\u51fa\u53bb\u7b49\u5f85\u7684\u90a3\u4e2a\u4eba\u518d\u6b21\u7ade\u4e89\u5230\u536b\u751f\u95f4\u8fdb\u53bb\u4e86\uff0c \u7136\u540e\u4f1a\u518d\u6b21\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\uff08\u5982\u4ee3\u7801\u4e2d\u7684\u6761\u4ef6\u5224\u65ad\uff09\uff0c\u53d1\u73b0\u536b\u751f\u95f4\u6709\u7eb8\u4e86\uff0cok\u53ef\u4ee5\u65b9\u4fbf\u4e86\u3002\u8f93\u5165 [1,2,3] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5\uff0c\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\uff0c\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\u3002\u603b\u7ed3\uff1a \u4e92\u65a5\u9501\u5c31\u7c7b\u6bd4\u4e00\u4e2a\u5355\u4eba\u7528\u7684\u536b\u751f\u95f4\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/32596.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-24T12:18:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250424121800-680a2bf81b803.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32596.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/32596.html\",\"name\":\"c++ \u4e92\u65a5\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-24T12:18:01+00:00\",\"dateModified\":\"2025-04-24T12:18:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/32596.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/32596.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32596.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"c++ \u4e92\u65a5\u9501\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"c++ \u4e92\u65a5\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/32596.html","og_locale":"zh_CN","og_type":"article","og_title":"c++ \u4e92\u65a5\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb338\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf5\u6b21\u3002\u5982\u679c\u4e00\u4e2a\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u540e\u53d1\u73b0\u4e0d\u6ee1\u8db3\u529e\u4e8b\u6761\u4ef6\uff0c\u6bd4\u5982\u6ca1\u5e26\u7eb8\uff08\u5982\u793a\u4f8b\u4ee3\u7801\u4e2d\u5224\u65ad\u4e0d\u6ee1\u8db3\u6267\u884c\u6761\u4ef6\uff09\uff0c\u6b64\u65f6\u51fa\u53bb\u7b49\u5f85\uff08\u5982\u793a\u4f8b\u4ee3\u7801\u7684wait\u51fd\u6570\u91ca\u653e\u9501\uff09\uff0c\u522b\u4eba\u8fdb\u53bb\u536b\u751f\u95f4\u5b8c\u4e8b\u540e\u51fa\u6765\u901a\u77e5\u8bf4\u4ed6\u7528\u5b8c\u4e86\uff0c\u7136\u540e\u521a\u624d\u51fa\u53bb\u7b49\u5f85\u7684\u90a3\u4e2a\u4eba\u518d\u6b21\u7ade\u4e89\u5230\u536b\u751f\u95f4\u8fdb\u53bb\u4e86\uff0c \u7136\u540e\u4f1a\u518d\u6b21\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\uff08\u5982\u4ee3\u7801\u4e2d\u7684\u6761\u4ef6\u5224\u65ad\uff09\uff0c\u53d1\u73b0\u536b\u751f\u95f4\u6709\u7eb8\u4e86\uff0cok\u53ef\u4ee5\u65b9\u4fbf\u4e86\u3002\u8f93\u5165 [1,2,3] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5\uff0c\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\uff0c\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\u3002\u603b\u7ed3\uff1a \u4e92\u65a5\u9501\u5c31\u7c7b\u6bd4\u4e00\u4e2a\u5355\u4eba\u7528\u7684\u536b\u751f\u95f4\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/32596.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-24T12:18:01+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250424121800-680a2bf81b803.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/32596.html","url":"https:\/\/www.wsisp.com\/helps\/32596.html","name":"c++ \u4e92\u65a5\u9501 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-24T12:18:01+00:00","dateModified":"2025-04-24T12:18:01+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/32596.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/32596.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/32596.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"c++ \u4e92\u65a5\u9501"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=32596"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32596\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/32594"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=32596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=32596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=32596"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=32596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}