{"id":111622,"date":"2026-10-01T11:22:54","date_gmt":"2026-10-01T03:22:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/111622.html"},"modified":"2026-10-01T11:22:54","modified_gmt":"2026-10-01T03:22:54","slug":"c%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86-%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/111622.html","title":{"rendered":"C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001032253-6abdd20d188c6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p align=\"center\"><font color=\"#0066ff\">\u0f3a \u4e2a\u4eba\u4e3b\u9875 \u00b7 \u7eaa\u5ff5229 \u0f3b<\/font><\/p>\n<p align=\"center\"><font color=\"#0099ff\">&#x1f3e0;\u6211\u7684\u535a\u5ba2\u4e3b\u9875&#x1f3e0;<\/font><\/p>\n<p align=\"center\"><font color=\"#3488ee\">\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u6570\u636e\u7ed3\u6784\u300b\u0f12<\/font><\/p>\n<p align=\"center\"><font color=\"#00cc66\">\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u7b97\u6cd5\u300b\u0f12<\/font><\/p>\n<p align=\"center\"><font color=\"#ff8822\">\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aC&#043;&#043;\u300b\u0f12<\/font><\/p>\n<p align=\"center\"><font color=\"#ffaa00\">\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aMySQL\u6570\u636e\u5e93\u300b\u0f12<\/font><\/p>\n<p align=\"center\"><font color=\"#4499ff\">\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u524d\u7aef\u5f00\u53d1\u300b\u0f12<\/font><\/p>\n<p align=\"center\"><font color=\"#ff6666\">\u0f12\u5176\u5b83\u6709\u8da3\u7684\u8ba1\u7b97\u673a\u77e5\u8bc6\u0f12<\/font><\/p>\n<p align=\"center\"><font color=\"#9933cc\">\u0f3a\u4e16\u4e0a\u672c\u6ca1\u6709\u8def&#xff0c;\u8d70\u7684\u4eba\u591a\u4e86\u81ea\u7136\u5c31\u6709\u4e86\u0f3b<\/font><\/p>\n<hr \/>\n<p>\u672c\u7bc7\u6587\u7ae0\u8bb2\u8ff0\u7684\u662fC&#043;&#043;\u5185\u5b58\u7ba1\u7406\u548c\u6a21\u677f\u7684\u5185\u5bb9&#xff0c;\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9<\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ee5\u4ee3\u7801\u7684\u5f62\u5f0f\u8bb2\u89e3<\/p>\n<hr \/>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>1.\u5185\u5b58\u7ba1\u7406<\/li>\n<li>2.\u6a21\u677f<\/li>\n<\/ul>\n<hr \/>\n<h2>1.\u5185\u5b58\u7ba1\u7406<\/h2>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span><span class=\"token string\">&lt;iostream&gt;<\/span><\/span><br \/>\nusing namespace std<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/class A<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/public:<\/span><br \/>\n<span class=\"token comment\">\/\/A(int a &#061; 0)<\/span><br \/>\n<span class=\"token comment\">\/\/:_a(a)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; &#034;A(int a &#061; 0)&#034; &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/~A()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; &#034;~A()&#034; &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/private:<\/span><br \/>\n<span class=\"token comment\">\/\/int _a;<\/span><br \/>\n<span class=\"token comment\">\/\/};<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/A* p5 &#061; (A*)malloc(sizeof(A) * 10);<\/span><br \/>\n<span class=\"token comment\">\/\/free(p5);<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/A* p6 &#061; new A[10];<\/span><br \/>\n<span class=\"token comment\">\/\/delete[] p6;<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u8fd9\u91cc\u8bb2\u7684\u662fmalloc\u4e0enew\u7533\u8bf7\u7a7a\u95f4\u548c\u9500\u6bc1\u7684\u65b9\u5f0f&#xff0c;\u4e4b\u524d\u6587\u7ae0\u89e3\u91ca\u8fc7\u8fd9\u91cc\u5c31\u4e0d\u8d58\u8ff0\u4e86<\/p>\n<p><span class=\"token comment\">\/\/#define _DEBUG_BIT<\/span><\/p>\n<p><span class=\"token comment\">\/\/void func()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/for (size_t i &#061; 0; i &lt; 100000; i&#043;&#043;)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/int* p1 &#061; (int*)malloc(sizeof(int) * 1024 * 1024); \/\/4M<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/if (p1)<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/cout &lt;&lt; i &lt;&lt; &#034;-&gt;&#034; &lt;&lt; p1 &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/else<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/break;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/#ifdef _DEBUG_BIT<\/span><br \/>\n<span class=\"token comment\">\/\/if (i &#061;&#061; 493)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/int x &#061; 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/#endif<\/span><br \/>\n<span class=\"token comment\">\/\/int* p1 &#061; new int[1024 * 1024];\/\/4M<\/span><br \/>\n<span class=\"token comment\">\/\/    \/\/\u7533\u8bf7\u5931\u8d25\u81ea\u52a8\u629b\u51fa\u5f02\u5e38<\/span><br \/>\n<span class=\"token comment\">\/\/ cout &lt;&lt; i &lt;&lt; &#034;-&gt;&#034; &lt;&lt; p1 &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u8fd9\u4e2a#define XX<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ <\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ #ifdef XX \/\/\u5982\u679c#define XX\u4ee3\u7801\u91cc\u7684\u4e1c\u897f\u624d\u80fd\u6267\u884c<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/    \u4ee3\u7801 <\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ #endif<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u4ee3\u7801\u91cc\u5199if \u6761\u4ef6\u662f i &#061;&#061; 397<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u76ee\u7684\u662f\u5728\u91cc\u9762\u6253\u4e00\u4e2a\u65ad\u70b9\u5f53\u6211\u4eec<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u5faa\u73af\u5230i &#061;&#061; 397 \u7684\u65f6\u5019\u518d\u770b<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u7528\u4e0d\u7740\u6211\u4eec\u4e00\u4e2a\u4e2a\u70b9\u5230\u7b2c397\u6b21\u5faa\u73af<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4e0d\u60f3\u7528\u8fd9\u6bb5\u4ee3\u7801\u5c06#define XX\u6ce8\u91ca\u5373\u53ef<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/#ifdef<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u4ee3\u7801   \u4e0d\u518d\u7f16\u8bd1<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ #endif<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/try\/catch\u5c31\u662f\u7ed9\u629b\u5f02\u5e38\u4ee3\u7801\u7684<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u7684\u63a5\u76d8\u673a\u5236\u8ba9\u7a0b\u5e8f\u6b7b\u7684\u4f53\u9762<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/try \u548c catch<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u7ed3\u6784<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ try<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ {<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/    \/\/\u53ef\u80fd\u51fa\u9519\u7684\u4ee3\u7801\u653e\u8fd9\u91cc<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ }<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ catch(\u5f02\u5e38\u7c7b\u578b  \u53d8\u91cf\u540d)<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ {<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/    \/\/\u51fa\u9519\u540e\u5904\u7406\u7684\u4ee3\u7801<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ }<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u5982\u679c\u4ee3\u7801\u91cc\u7684new\u5931\u8d25\u629b\u5f02\u5e38<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/catch\u5c31\u4f1a\u63a5\u6536\u5f02\u5e38<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u5e76\u6253\u51fa\u9519\u5728\u54ea\u91cc<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u5f02\u5e38\u6709\u591a\u79cd\u4e3e\u5217catch()<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/    \u8fd9\u4e9b\u90fd\u5728\u5c0f\u62ec\u53f7\u91cc<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ const bad_alloc&amp; e \u5185\u5b58\u4e0d\u8db3<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ const out_of_range&amp; e \u8d8a\u754c<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ const (std::)exception&amp; e<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/  \u7ee7\u627f\u81eastd::expection\u7684\u6807\u51c6\u5f02\u5e38<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u5982std::runtime_error std::out_of_range<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u8fd9\u4e9b\u5f02\u5e38\u7c7b\u578b\u90fd\u5728std\u57df\u5185<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ <\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ const &#8230; \u5305\u542b\u6240\u6709\u5f02\u5e38<\/span><br \/>\n<span class=\"token comment\">\/\/try<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/func();<\/span><br \/>\n<span class=\"token comment\">\/\/    }<\/span><br \/>\n<span class=\"token comment\">\/\/catch (const exception&amp; e)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u8fd9\u91cc\u4e3a\u5565\u4e0d\u7528exception e<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u539f\u56e0:exception\u662f\u7c7b\u4e0d\u52a0const &amp;\u4f1a\u89e6\u53d1\u62f7\u8d1d\u6784\u9020 <\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt;  e.what() &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4ee3\u7801\u91cc\u7684what()\u51fd\u6570\u662fexception\u7c7b\u7684\u4e00\u4e2a\u6210\u5458\u51fd\u6570<\/span><br \/>\n<span class=\"token comment\">\/\/    \/\/\u8fd4\u56de\u6709\u9519\u8bef\u4fe1\u606f\u7684\u5b57\u7b26\u4e32<\/span><br \/>\n<span class=\"token comment\">\/\/    \/\/&#xff08;\u9519\u8bef\u4fe1\u606f\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u7531\u629b\u5f02\u5e38\u7684\u5730\u65b9\u51b3\u5b9a&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u5148\u89e3\u91camain\u51fd\u6570\u91cc\u7684 try { \/\/\u4ee3\u7801&#xff08;\u53ef\u80fd\u51fa\u73b0\u7684\u4ee3\u7801&#xff09; } catch(\u5f02\u5e38\u7c7b\u578b \u53d8\u91cf\u540d) { \/\/\u51fa\u9519\u540e\u5904\u7406\u7684\u4ee3\u7801 } \u4e00\u822c\u662fnew\u7533\u8bf7\u7a7a\u95f4\u5931\u8d25\u629b\u5f02\u5e38 \u4ee3\u7801\u91cc\u7684new\u5931\u8d25\u629b\u5f02\u5e38 catch\u5c31\u4f1a\u63a5\u6536\u5f02\u5e38 \u5e76\u6253\u51fa\u5f02\u5e38\u5728\u4ee3\u7801\u90a3\u4e00\u884c<\/p>\n<p>\u5f02\u5e38\u53ef\u4ee5\u662f\u4efb\u4f55\u7c7b\u578b(\u6700\u5e38\u89c1\u7684\u662fnew\u629b\u5f02\u5e38\u7c7b\u578bexpection) \u4e3e\u5217catch() \u8fd9\u4e9b\u90fd\u5728\u5c0f\u62ec\u53f7\u91cc \u8fd4\u56de\u610f\u601d const bad_alloc&amp; e \u5185\u5b58\u4e0d\u8db3 const out_of_range&amp; e \u8d8a\u754c const (std::)expection\u7684\u6807\u51c6\u5f02\u5e38 \u5982std::runtime_error std::out_of_range(\u8fd9\u4e9b\u5f02\u5e38\u7c7b\u578b\u90fd\u5728std\u57df\u5185)<\/p>\n<p>\u2026(\u8868\u793a\u6240\u6709\u5f02\u5e38)<\/p>\n<p>try<br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/func();<\/span><br \/>\n<span class=\"token comment\">\/\/    }<\/span><br \/>\n<span class=\"token comment\">\/\/catch (const exception&amp; e)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u8fd9\u91cc\u4e3a\u5565\u4e0d\u7528exception e<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/ \u539f\u56e0:exception\u662f\u7c7b\u4e0d\u52a0const &amp;\u4f1a\u89e6\u53d1\u62f7\u8d1d\u6784\u9020 <\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt;  e.what() &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4ee3\u7801\u91cc\u7684what()\u51fd\u6570\u662fexception\u7c7b\u7684\u4e00\u4e2a\u6210\u5458\u51fd\u6570<\/span><br \/>\n<span class=\"token comment\">\/\/    \/\/\u8fd4\u56de\u6709\u9519\u8bef\u4fe1\u606f\u7684\u5b57\u7b26\u4e32<\/span><br \/>\n<span class=\"token comment\">\/\/    \/\/&#xff08;\u9519\u8bef\u4fe1\u606f\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u7531\u629b\u5f02\u5e38\u7684\u5730\u65b9\u51b3\u5b9a&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u8fd9\u91cc\u4e3a\u5565\u4e0d\u7528expection e \u6211\u4eec\u77e5\u9053expection \u8fd9\u662f\u4e00\u4e2a\u7c7b \u6211\u4eec\u5728\u5f62\u53c2\u8fd9\u6837\u5199\u4f1a\u8c03\u7528\u62f7\u8d1d\u6784\u9020<\/p>\n<p>\u8fd9\u91ccwhat()\u662f\u4ec0\u4e48 \u9996\u5148\u6211\u4eec\u77e5\u9053e\u662fexpection\u7c7b\u7c7b\u578b what\u662f\u8be5\u7c7b\u4e2d\u7684\u6210\u5458\u51fd\u6570&#xff08;\u4f5c\u7528\u662f\u6253\u5370\u629b\u5f02\u5e38\u7684\u90a3\u4e00\u884c\u4ee3\u7801&#xff09;<\/p>\n<p>\u63a5\u4e0b\u6765\u8bb2\u89e3\u9884\u5904\u7406\u6307\u4ee4 \/\/#define _DEBUG_BIT \u8fd9\u4e2a\u7684\u610f\u601d\u5c31\u662f\u5b9a\u4e49_DEBUG_BIT\u8fd9\u4e2a\u4e1c\u897f<\/p>\n<p>\u4e0b\u9762\u4e24\u4e2a\u9884\u5904\u7406\u6307\u4ee4\u914d\u5957 \/\/#ifdef _DEBUG_BIT \/\/#endif<\/p>\n<p>\u6307\u4ee4\u540e\u9762\u7684\u4e1c\u897f\u5c31\u662f\u4e2a\u540d\u5b57<\/p>\n<p><span class=\"token comment\">\/\/#ifdef _DEBUG_BIT    <\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>i <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">493<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/int x &#061; 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/#endif<\/span><\/p>\n<p>\u6211\u4e3b\u8981\u8bb2\u8fd9\u4e2a \u5982\u679c\u5b9a\u4e49\u4e86_DEBUG_BIT (#ifdef _DEBUG_BIT ) \u91cc\u9762\u7684\u51fd\u6570\u5c31\u53ef\u4ee5\u4f7f\u7528&#xff08;\u628a\u5b83\u6ce8\u91ca\u4e86\u6216\u8005\u6ca1\u5b9a\u4e49\u91cc\u9762\u7684\u51fd\u6570\u5c31\u4e0d\u53ef\u4ee5\u7528&#xff09;<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u8fd9\u8981\u7528\u4e8e\u8c03\u8bd5\u6211\u4eec\u7ed9\u6761\u4ef6\u8bed\u53e5\u91cc\u6253\u4e00\u4e2a\u65ad\u70b9 \u7b49\u5faa\u73af\u5230\u8fd9\u5c31\u8fdb\u5165\u6761\u4ef6\u8bed\u53e5\u4ee3\u7801\u8c03\u5f0f\u505c\u6b62<\/p>\n<p>\u5982\u679c\u4e0d\u7528\u8fd9\u4e2a\u4ee3\u7801\u6211\u4eec\u60f3\u770b\u7b2c493\u6b21\u5faa\u73af\u6211\u4eec\u8981\u70b9\u591a\u5c11\u65f6\u95f4<\/p>\n<p>\u6d6a\u8d39\u65f6\u95f4<\/p>\n<hr \/>\n<p><span class=\"token comment\">\/\/double Divide(int a, int b)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u5f53b &#061;&#061; 0\u65f6\u629b\u51fa\u5f02\u5e38<\/span><br \/>\n<span class=\"token comment\">\/\/if (b &#061;&#061; 0)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/string s(&#034;Divide by zero condition!&#034;);<\/span><br \/>\n<span class=\"token comment\">\/\/throw s;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/else<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/return ((double)a \/ (double)b);<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; __FUNCTION__ &lt;&lt; &#034;:&#034; &lt;&lt; __LINE__ &lt;&lt; &#034;\u884c\u6267\u884c&#034;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u8fd9\u4e24\u4e2a\u662f\u5b8f\u5b9a\u4e49\u6807\u8bc6\u7b26<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/__FUNCTION__ \u5c55\u5f00\u6210\u5f53\u524d\u884c\u53f7<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/__LINE__\u5c55\u5f00\u6210\u5f53\u524d\u51fd\u6570\u540d<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4e4b\u524d\u5199\u7684FUNCTION   LINE<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/\u6ca1\u5728\u5de6\u53f3\u4e24\u8fb9\u5404\u52a0\u4e24\u4e2a\u4e0b\u5212\u7ebf<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u7531\u4e8e\u6ca1\u6709&#034;&#034;\u4e0d\u4f1a\u5f53\u6210\u5b57\u7b26\u4e32<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4e0d\u52a0&#034;&#034;\u7684\u5b57\u7b26\u4e32\u4f1a\u5f53\u6210\u540d\u5b57\u53bb\u5168\u5c40\u91cc\u627e\u627e\u4e0d\u5230\u5c31\u62a5\u672a\u5b9a\u4e49<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/&lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/void main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/int len, time;<\/span><br \/>\n<span class=\"token comment\">\/\/cin &gt;&gt; len &gt;&gt; time;<\/span><br \/>\n<span class=\"token comment\">\/\/try<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Divide(len, time) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/catch (const string&amp; errmsg)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; errmsg &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u8fd9\u91cc\u7684catch\u91cc\u653e\u7684string\u5f02\u5e38 \u4ee3\u7801\u91cc\u4e5f\u662f throw s<\/p>\n<p>\u4e00\u822c\u7528new\u629b\u5f02\u5e38\u5c31\u4f1a\u81ea\u52a8throw \u5176\u5b83\u7c7b\u578b\u629b\u5f02\u5e38\u4e00\u822c\u5c31\u662f\u8981\u624b\u52a8throw\u629b\u5f02\u5e38<\/p>\n<p><span class=\"token keyword\">double<\/span> <span class=\"token function\">Divide<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> b<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u5f53b &#061;&#061; 0\u65f6\u629b\u51fa\u5f02\u5e38<\/span><br \/>\n<span class=\"token comment\">\/\/if (b &#061;&#061; 0)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/string s(&#034;Divide by zero condition!&#034;);<\/span><br \/>\n<span class=\"token comment\">\/\/throw s;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/else<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/return ((double)a \/ (double)b);<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; __FUNCTION__ &lt;&lt; &#034;:&#034; &lt;&lt; __LINE__ &lt;&lt; &#034;\u884c\u6267\u884c&#034;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u8fd9\u4e24\u4e2a\u662f\u5b8f\u5b9a\u4e49\u6807\u8bc6\u7b26<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/__FUNCTION__ \u5c55\u5f00\u6210\u5f53\u524d\u884c\u53f7<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/__LINE__\u5c55\u5f00\u6210\u5f53\u524d\u51fd\u6570\u540d<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4e4b\u524d\u5199\u7684FUNCTION   LINE<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/\u6ca1\u5728\u5de6\u53f3\u4e24\u8fb9\u5404\u52a0\u4e24\u4e2a\u4e0b\u5212\u7ebf<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u7531\u4e8e\u6ca1\u6709&#034;&#034;\u4e0d\u4f1a\u5f53\u6210\u5b57\u7b26\u4e32<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4e0d\u52a0&#034;&#034;\u7684\u5b57\u7b26\u4e32\u4f1a\u5f53\u6210\u540d\u5b57\u53bb\u5168\u5c40\u91cc\u627e\u627e\u4e0d\u5230\u5c31\u62a5\u672a\u5b9a\u4e49<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/&lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u8fd9\u91cc\u5c31\u662f\u9632\u6b62\u5206\u6bcd\u4e3a0\u5c31\u5f04\u4e00\u4e2astring\u7c7b\u578b\u7684 s thow \u5c31\u662f\u629b\u5f02\u5e38catch\u5c31\u63a5\u6536\u5e76\u6253\u5370\u5f02\u5e38\u539f\u56e0<\/p>\n<p>cout &lt;&lt; __FUNCTION__ &lt;&lt; &#034;:&#034; &lt;&lt; __LINE__ &lt;&lt; &#034;\u884c\u6267\u884c&#034;<\/p>\n<p>\u8fd9\u4e24\u4e2a\u662f\u5b8f\u5b9a\u4e49\u6807\u8bc6\u7b26<\/p>\n<p>\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u5de6\u53f3\u4e24\u8fb9\u90fd\u5fc5\u987b\u5404\u6709\u4e24\u4e2a\u4e0b\u5212\u7ebf<\/p>\n<p>\u5426\u5219\u5c31\u662f\u540d\u5b57&#xff08;\u4f1a\u4ece\u6587\u4ef6\u91cc\u627e\u51fd\u6570\u540d\u3001\u7c7b\u540d\u7b49\u627e\u4e0d\u5230\u5c31\u62a5\u672a\u5b9a\u4e49&#xff09;<\/p>\n<p>\u7528&#034; &#034;\u5c31\u6253\u5370\u7684\u662f\u5b57\u7b26\u4e32<\/p>\n<p>\u4f5c\u7528 FUNCTION \u5c55\u5f00\u5f53\u524d\u884c\u53f7<\/p>\n<p>LINE \u5c55\u5f00\u5f53\u524d\u51fd\u6570\u540d<\/p>\n<hr \/>\n<p><span class=\"token comment\">\/\/typedef int STDataType;<\/span><br \/>\n<span class=\"token comment\">\/\/class Stack<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/public:<\/span><br \/>\n<span class=\"token comment\">\/\/Stack(int n &#061; 4)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; &#034;Stack(int n &#061; 4)&#034; &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/    <\/span><br \/>\n<span class=\"token comment\">\/\/_a &#061; (STDataType*)malloc(sizeof(STDataType) * n);<\/span><br \/>\n<span class=\"token comment\">\/\/if (_a &#061;&#061; nullptr)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/perror(&#034;malloc\u7533\u8bf7\u7a7a\u95f4\u5931\u8d25&#034;);<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/perror\u5934\u6587\u4ef6#inlcude&lt;cstdio&gt;<\/span><br \/>\n<span class=\"token comment\">\/\/return;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/_capacity &#061; n;<\/span><br \/>\n<span class=\"token comment\">\/\/_top &#061; 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/~Stack()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; &#034;~Stack()&#034; &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/free(_a);<\/span><br \/>\n<span class=\"token comment\">\/\/_a &#061; nullptr;<\/span><br \/>\n<span class=\"token comment\">\/\/_capacity &#061; _top &#061; 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/private:<\/span><br \/>\n<span class=\"token comment\">\/\/STDataType* _a;<\/span><br \/>\n<span class=\"token comment\">\/\/size_t _capacity;<\/span><br \/>\n<span class=\"token comment\">\/\/size_t _top;<\/span><br \/>\n<span class=\"token comment\">\/\/};<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/Stack* p1 &#061; new Stack[10];<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/delete p1;<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int* p2 &#061; new int(1);<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/free(p2);<\/span><br \/>\n<span class=\"token comment\">\/\/delete p2;<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u8fd9\u91cc\u5c31\u662f\u901a\u8fc7new\u7533\u8bf7\u7a7a\u95f4\u7ed9\u7a7a\u95f4\u7684\u5143\u7d20\u521d\u59cb\u5316 \u7136\u540e\u9500\u6bc1\u7a7a\u95f4<\/p>\n<p>new\u6bd4malloc\u591a\u4e86\u4e00\u4e2a\u81ea\u52a8\u8c03\u7528\u6784\u9020\u51fd\u6570<\/p>\n<p>delete \u6bd4free\u591a\u4e86\u4e00\u4e2a\u6790\u6784\u51fd\u6570<\/p>\n<p>\u8fd9\u91cc\u7684delete p1;\u56e0\u8be5\u6539\u4e3adelete[] p1\u56e0\u4e3a\u8fd9\u6837\u53ea\u4f1a\u8c03\u7528\u4e00\u6b21\u6790\u6784\u51fd\u6570<\/p>\n<p>\u8fd9\u6837\u5199\u5728VS\u4f1a\u62a5\u9519&#xff08;VS\u8f83\u4e25\u683c&#xff09;\u653e\u5728\u9898\u76ee\u4e0d\u4f1a\u62a5\u9519<\/p>\n<p><span class=\"token comment\">\/\/class A<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/public:<\/span><br \/>\n<span class=\"token comment\">\/\/A(int a &#061; 0)<\/span><br \/>\n<span class=\"token comment\">\/\/:_a(a)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; &#034;A(int a &#061; 0)&#034; &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/~A()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; &#034;~A()&#034; &lt;&lt; this &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/private:<\/span><br \/>\n<span class=\"token comment\">\/\/int _a;<\/span><br \/>\n<span class=\"token comment\">\/\/};<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/\/*A* p1 &#061; new A[10];<\/span><br \/>\n<span class=\"token comment\">\/\/delete[] p1;*\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/A* p1 &#061; (A*)malloc(sizeof(A));<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/malloc\u4e0d\u80fd\u8c03\u7528\u6784\u9020<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u4e0d\u80fd\u8fd9\u6837\u663e\u793a\u8c03\u7528\u6784\u9020<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/p1-&gt;A(1);<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u8981\u8fd9\u6837<\/span><br \/>\n<span class=\"token comment\">\/\/new (p1)A(1);<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u8fd9\u91cc\u7684A(1)\u4e0d\u662f\u9ed8\u8ba4\u5bf9\u8c61<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/\u8fd9\u4e2a\u5c31\u662f\u5728p1\u5185\u5b58\u4e2d\u8c03\u7528\u6784\u9020\u51fd\u6570<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/ <\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/ new A(1)<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/ \u8fd9\u4e2a\u662f\u7533\u8bf7\u4e00\u4e2a\u7a7a\u95f4\u5728\u8c03\u7528\u6784\u9020<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/ <\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/ new (p1)A(1);<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/ \u8fd9\u4e2a\u662f\u76f4\u63a5\u5728p1\u5730\u5740\u4e0a\u8c03\u7528\u6784\u9020\u51fd\u6570<\/span><br \/>\n<span class=\"token comment\">\/\/ \/\/ <\/span><br \/>\n<span class=\"token comment\">\/\/\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u53ef\u4ee5\u6790\u6784<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/p1-&gt;~A();<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/free(p1);<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>malloc\u7684\u5bf9\u8c61\u4e0d\u80fd\u81ea\u52a8\u8c03\u7528\u6784\u9020\u51fd\u6570\u53ef\u4ee5\u8c03\u7528\u6790\u6784\u51fd\u6570&#xff08;\u8981\u624b\u52a8\u8c03\u7528&#xff09; p1-&gt;~A();<\/p>\n<p>malloc\u7684\u5bf9\u8c61\u8c03\u7528\u6784\u9020\u51fd\u6570\u8981\u8c03\u7528 new (p1)A(1);<\/p>\n<p>\u610f\u601d\u662f\u8c03\u7528\u6784\u9020\u51fd\u6570\u4f20\u5165\u5b9e\u53c21&#xff0c;\u8fd9\u4e2a\u5bf9\u8c61\u5728p1\u8fd9\u4e2a\u5730\u5740\u4e2d\u6784\u9020&#xff0c;\u6700\u540e\u8fd4\u56de\u6307\u9488<\/p>\n<p>new (p1)A(1); new A(1);<\/p>\n<p>\u533a\u522b\u4e00\u4e2a\u5df2\u6709\u5730\u5740\u628a\u6784\u9020\u5bf9\u8c61\u653e\u5728\u5185\u5b58<\/p>\n<p>\u4e00\u4e2a\u5411\u7a7a\u95f4\u7533\u8bf7\u4e4b\u540e\u8c03\u7528\u6784\u9020\u51fd\u6570<\/p>\n<hr \/>\n<h2>2.\u6a21\u677f<\/h2>\n<p>C&#043;&#043;\u6a21\u677f\u5206\u4e3a \u51fd\u6570\u6a21\u677f \u7c7b\u6a21\u677f<\/p>\n<p>\u4f5c\u7528&#xff1a;\u7b80\u5316\u4ee3\u7801\u51cf\u5c11\u903b\u8f91\u91cd\u590d\u6027\u4ee3\u7801<\/p>\n<p>\u6211\u4eec\u6765\u770b\u770b\u51fd\u6570\u91cd\u8f7d\u4e0e\u51fd\u6570\u6a21\u677f<\/p>\n<p><span class=\"token comment\">\/\/void Swap(int&amp; left, int&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/int temp &#061; left;<\/span><br \/>\n<span class=\"token comment\">\/\/left &#061; right;<\/span><br \/>\n<span class=\"token comment\">\/\/right &#061; temp;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/void Swap(double&amp; left, double&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/double temp &#061; left;<\/span><br \/>\n<span class=\"token comment\">\/\/left &#061; right;<\/span><br \/>\n<span class=\"token comment\">\/\/right &#061; temp;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/void Swap(char&amp; left, char&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/char temp &#061; left;<\/span><br \/>\n<span class=\"token comment\">\/\/left &#061; right;<\/span><br \/>\n<span class=\"token comment\">\/\/right &#061; temp;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u51fd\u6570\u6a21\u677f<\/span><br \/>\n<span class=\"token comment\">\/\/\u6cdb\u578b\u7f16\u7a0b<\/span><br \/>\n<span class=\"token comment\">\/\/\u9488\u5bf9\u4efb\u610f\u7c7b\u578b\u7684\u5bf9\u8c61\u4ea4\u6362<\/span><br \/>\n<span class=\"token comment\">\/\/ <\/span><br \/>\n<span class=\"token comment\">\/\/\u51fd\u6570\u6a21\u677f\u5185\u5bb9\u4e0e\u666e\u901a\u51fd\u6570\u76f8\u540c\u65f6<\/span><br \/>\n<span class=\"token comment\">\/\/ \u51fd\u6570\u6a21\u677f\u4e00\u822c\u5199\u5728\u5934\u6587\u4ef6<\/span><br \/>\n<span class=\"token comment\">\/\/\u76f8\u540c\u65f6\u4f18\u5148\u7528\u666e\u901a\u51fd\u6570<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u7ed3\u6784<\/span><br \/>\n<span class=\"token comment\">\/\/template&lt;typename\/class \u7c7b\u578b\u540d&gt;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u4e00\u822c\u7528typename<\/span><br \/>\n<span class=\"token comment\">\/\/ void  \u51fd\u6570\u540d(\u7c7b\u578b\u540d \u5bf9\u8c61\u540d)<\/span><br \/>\n<span class=\"token comment\">\/\/ {<\/span><br \/>\n<span class=\"token comment\">\/\/  \u5185\u5bb9<\/span><br \/>\n<span class=\"token comment\">\/\/ <\/span><br \/>\n<span class=\"token comment\">\/\/ }<\/span><\/p>\n<p><span class=\"token comment\">\/\/template&lt;typename T&gt;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/template\u4e0d\u8981\u5934\u6587\u4ef6C&#043;&#043;\u81ea\u5e26<\/span><br \/>\n<span class=\"token comment\">\/\/void Swap(T&amp; left, T&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/T temp &#061; left;<\/span><br \/>\n<span class=\"token comment\">\/\/left &#061; right;<\/span><br \/>\n<span class=\"token comment\">\/\/right &#061; temp;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/int i &#061; 0, j &#061; 1;<\/span><br \/>\n<span class=\"token comment\">\/\/double x &#061; 1.1, y &#061; 2.2;<\/span><br \/>\n<span class=\"token comment\">\/\/Swap(i, j);<\/span><br \/>\n<span class=\"token comment\">\/\/Swap(x, y);<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u51fd\u6570\u91cd\u8f7d\u5c31\u4e0d\u8d58\u8ff0\u4e86&#xff0c;\u5c31\u662f\u5199\u4e86\u4ea4\u6362\u51fd\u6570<\/p>\n<p>\u51fd\u6570\u6a21\u677f\u7ed3\u6784<\/p>\n<p>template&lt;typename\/class \u7c7b\u578b\u540d&gt;<\/p>\n<p>templateC&#043;&#043;\u81ea\u5e26\u65e0\u5934\u6587\u4ef6<\/p>\n<p>typename\/class\u90fd\u53ef\u4ee5\u7528<\/p>\n<p>\u4ee5\u4ea4\u6362\u51fd\u6570\u4e3a\u4f8b<\/p>\n<p><span class=\"token comment\">\/\/template&lt;typename T&gt;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/template\u4e0d\u8981\u5934\u6587\u4ef6C&#043;&#043;\u81ea\u5e26<\/span><br \/>\n<span class=\"token comment\">\/\/void Swap(T&amp; left, T&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/T temp &#061; left;<\/span><br \/>\n<span class=\"token comment\">\/\/left &#061; right;<\/span><br \/>\n<span class=\"token comment\">\/\/right &#061; temp;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u53ef\u4ee5\u4f20\u4efb\u4f55\u5185\u7f6e\u7c7b\u578b<\/p>\n<p>\u8fdb\u884c\u4ea4\u6362<\/p>\n<p><span class=\"token comment\">\/\/template&lt;class T&gt;<\/span><br \/>\n<span class=\"token comment\">\/\/T Add(const T&amp; left, const T&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/return left &#043; right;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/template&lt;class T1, class T2&gt;<\/span><br \/>\n<span class=\"token comment\">\/\/void func(const T1&amp; left, const T2&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{ }<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/int a1 &#061; 10, a2 &#061; 20;<\/span><br \/>\n<span class=\"token comment\">\/\/double d1 &#061; 10.1, d2 &#061; 20.1;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u9690\u5f0f\u5b9e\u4f8b\u5316(\u5b9e\u53c2\u7c7b\u578b\u63a8\u6f14\u6a21\u677f\u53c2\u6570)<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add(a1, a2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add(d1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add(a1, (int)d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add((double)a1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u663e\u793a\u5b9e\u4f8b\u5316 &#xff08;\u663e\u793a\u6307\u5b9a\u6a21\u677f\u53c2\u6570&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add&lt;int&gt;(a1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add&lt;double&gt;(a1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add&lt;int&gt;(d1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u8fd9\u91cc\u8bb2\u4e00\u4e0b\u8c03\u7528\u65f6\u5982\u679c\u5b9e\u53c2\u7c7b\u578b\u4e0d\u540c\u6216\u8005\u60f3\u6539\u53d8\u5b9e\u53c2\u7c7b\u578b\u8981\u7528\u9690\u5f0f\u5b9e\u4f8b\u5316\u6216\u663e\u793a\u5b9e\u4f8b\u5316<\/p>\n<p><span class=\"token comment\">\/\/\/\/\u663e\u793a\u5b9e\u4f8b\u5316 &#xff08;\u663e\u793a\u6307\u5b9a\u6a21\u677f\u53c2\u6570&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add&lt;int&gt;(a1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add&lt;double&gt;(a1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add&lt;int&gt;(d1, d2) &lt;&lt; endl;<\/span><\/p>\n<p>\u663e\u793a\u5b9e\u4f8b\u5316 Add(a1, d2) \u5c31\u662f\u5728\u51fd\u6570\u540d\u4e0e\u5c0f\u62ec\u53f7\u4e4b\u95f4\u52a0\u4e2a&lt;&gt; &lt;&gt;\u91cc\u9762\u5c31\u662f\u60f3\u8981\u8f6c\u6362\u7684\u7c7b\u578b<\/p>\n<p>\u9690\u5f0f\u5b9e\u4f8b\u5316 Add(a1, (int)d2 \u5c31\u662f\u76f4\u63a5\u5c06\u5b9e\u53c2\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/p>\n<hr \/>\n<p><span class=\"token comment\">\/\/\u4e13\u95e8\u5904\u7406int\u7684\u52a0\u6cd5\u51fd\u6570<\/span><br \/>\n<span class=\"token comment\">\/\/int Add(int left, int right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/return left &#043; right;<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u901a\u7528\u52a0\u6cd5\u51fd\u6570<\/span><br \/>\n<span class=\"token comment\">\/\/template&lt;class T&gt;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/Add\u51fd\u6570\u8fd4\u56de\u503c\u662fint \u4e0d\u662fvoid<\/span><br \/>\n<span class=\"token comment\">\/\/int Add(const T&amp; left, const T&amp; right)<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/return left &#043; right &#043; 10;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/int a1 &#061; 10, a2 &#061; 20;<\/span><br \/>\n<span class=\"token comment\">\/\/double d1 &#061; 10.1, d2 &#061; 20.1;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u9690\u5f0f\u5b9e\u4f8b\u5316(\u5b9e\u53c2\u7c7b\u578b\u63a8\u6f14\u6a21\u677f\u53c2\u6570)<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add(a1, a2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u666e\u901a\u51fd\u6570\u548c\u51fd\u6570\u6a21\u677f\u4f1a\u8fdb\u884c\u91cd\u8f7d\u534f\u8bae<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u82e5\u662f\u5339\u914d\u5ea6\u4e00\u6837\u7684\u8bdd\u4f18\u5148\u7528\u666e\u901a\u51fd\u6570<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add(d1, d2) &lt;&lt; endl;<\/span><br \/>\n<span class=\"token comment\">\/\/cout &lt;&lt; Add&lt;int&gt;(a1, a2);<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u5728\u5339\u914d\u5ea6\u76f8\u540c\u7684\u60c5\u51b5\u4e0b\u7528\u7684(\u5339\u914d\u5ea6\u6307\u7684\u662f\u6bd4\u8f83\u8fd4\u56de\u503c\u3001\u51fd\u6570\u540d\u3001\u5f62\u53c2)<\/span><br \/>\n<span class=\"token comment\">\/\/\/\/\u663e\u793a\u5b9e\u4f8b\u8c03\u7528\u7684\u662f\u51fd\u6570\u6a21\u677f<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>\u8fd9\u91cc\u8bb2\u4e2a\u51fd\u6570\u7684\u5339\u914d\u5ea6 \u8fd4\u56de\u7c7b\u578b \u51fd\u6570\u540d \u5f62\u53c2 \u76f8\u540c\u5c31\u662f\u5b8c\u5168\u5339\u914d<\/p>\n<p>\u5f53\u51fd\u6570\u91cd\u8f7d\u548c\u51fd\u6570\u6a21\u677f\u4e2d\u6709\u5b8c\u5168\u5339\u914d\u7684\u51fd\u6570\u5c31\u4f1a\u89e6\u53d1\u91cd\u8f7d\u534f\u8bae \u4f18\u5148\u8c03\u7528\u666e\u901a\u51fd\u6570&#xff08;\u51fd\u6570\u91cd\u8f7d&#xff09;&#xff0c;\u51fd\u6570\u5185\u5bb9\u6709\u5dee\u5f02\u65e0\u59a8<\/p>\n<hr \/>\n<p>\u7c7b\u6a21\u677f<\/p>\n<p><span class=\"token comment\">\/\/typedef double DateType;<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/namespace bit<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/class stack<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/private:<\/span><br \/>\n<span class=\"token comment\">\/\/DateType* _a;<\/span><br \/>\n<span class=\"token comment\">\/\/int _top;<\/span><br \/>\n<span class=\"token comment\">\/\/int _capacity;<\/span><br \/>\n<span class=\"token comment\">\/\/};<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/int main()<\/span><br \/>\n<span class=\"token comment\">\/\/{<\/span><br \/>\n<span class=\"token comment\">\/\/bit::stack st1;\/\/int<\/span><br \/>\n<span class=\"token comment\">\/\/bit::stack st2;\/\/double<\/span><br \/>\n<span class=\"token comment\">\/\/<\/span><br \/>\n<span class=\"token comment\">\/\/return 0;<\/span><br \/>\n<span class=\"token comment\">\/\/}<\/span><\/p>\n<p>namespace bit<br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token comment\">\/\/\u7c7b\u6a21\u677f(\u7528\u6cd5\u4e0e\u7c7b\u51fd\u6570\u5dee\u4e0d\u591a)<\/span><br \/>\ntemplate<span class=\"token operator\">&lt;<\/span>class T<span class=\"token operator\">&gt;<\/span><br \/>\nclass stack<br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\npublic<span class=\"token operator\">:<\/span><br \/>\n<span class=\"token comment\">\/\/\u8fd9\u91cc\u8981\u52a0public:<\/span><br \/>\n<span class=\"token comment\">\/\/\u5426\u5219\u8c03\u7528\u4e0d\u4e86\u6784\u9020\u51fd\u6570<\/span><br \/>\n<span class=\"token function\">stack<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> n <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">:<\/span><span class=\"token function\">_a<\/span><span class=\"token punctuation\">(<\/span>new T<span class=\"token punctuation\">[<\/span>n<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">,<\/span> <span class=\"token function\">_top<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">,<\/span> <span class=\"token function\">_capacity<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;stack(int n &#061; 4)&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> T<span class=\"token operator\">&amp;<\/span> x<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token comment\">\/\/..\u6269\u5bb9<\/span><br \/>\n_a<span class=\"token punctuation\">[<\/span>_top<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> x<span class=\"token punctuation\">;<\/span><br \/>\n_top<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token operator\">~<\/span><span class=\"token function\">stack<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token comment\">\/\/new\u7533\u8bf7\u4e86\u7a7a\u95f4\u6700\u540e\u8981\u9500\u6bc1<\/span><br \/>\ndelete<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> _a<span class=\"token punctuation\">;<\/span><br \/>\n_a <span class=\"token operator\">&#061;<\/span> nullptr<span class=\"token punctuation\">;<\/span><br \/>\n_top <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n_capacity <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;~stack()&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>private<span class=\"token operator\">:<\/span><br \/>\nT<span class=\"token operator\">*<\/span> _a<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _top<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _capacity<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\ntry<br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n       <span class=\"token comment\">\/\/\u663e\u793a\u5b9e\u4f8b\u5316<\/span><br \/>\nbit<span class=\"token operator\">::<\/span>stack <span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">&gt;<\/span> st1<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/\u7c7b\u6a21\u677f\u548c\u51fd\u6570\u6a21\u677f\u90fd\u53ef\u4ee5\u7528\u663e\u793a\u5b9e\u4f8b\u5316\u548c\u9690\u5f0f\u5b9e\u4f8b\u5316<\/span><br \/>\nbit<span class=\"token operator\">::<\/span>stack <span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span> st2<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u5bf9\u8c61\u901a\u8fc7\u7a7a\u95f4\u6784\u9020\u6210\u529f\u540e<\/span><br \/>\n<span class=\"token comment\">\/\/\u5bf9\u8c61\u5c31\u4e0d\u7528\u901a\u8fc7\u7a7a\u95f4\u8c03\u7528\u7a7a\u95f4\u91cc\u7684\u51fd\u6570<\/span><br \/>\nst1<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nst1<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nst1<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>st2<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1.1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nst2<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2.2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nst2<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">3.3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token function\">catch<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> exception<span class=\"token operator\">&amp;<\/span> e<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> e<span class=\"token punctuation\">.<\/span><span class=\"token function\">what<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7c7b\u6a21\u677f\u548c\u51fd\u6570\u6a21\u677f\u5dee\u4e0d\u591a\u8fd9\u91cc\u5c31\u4e0d\u8d58\u8ff0\u4e86<\/p>\n<p>\u6709\u4e86\u7c7b\u6a21\u677f\u6211\u4eec\u60f3\u6709\u4ec0\u4e48\u7c7b\u578b\u7684\u6808\u5c31\u7528\u4ec0\u4e48\u7c7b\u578b \u7b49\u2026<\/p>\n<hr \/>\n<p>\u6587\u7ae0\u5230\u6b64\u5c31\u544a\u4e00\u6bb5\u843d&#xff0c;\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9&#xff0c;\u611f\u8c22\u89c2\u770b&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0f3a \u4e2a\u4eba\u4e3b\u9875 \u00b7 \u7eaa\u5ff5229 \u0f3b<br \/>\n&#x1f3e0;\u6211\u7684\u535a\u5ba2\u4e3b\u9875&#x1f3e0;<br \/>\n\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u6570\u636e\u7ed3\u6784\u300b\u0f12<br \/>\n\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u7b97\u6cd5\u300b\u0f12<br \/>\n\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aC\u300b\u0f12<br \/>\n\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aMySQL\u6570\u636e\u5e93\u300b\u0f12<br \/>\n\u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u524d\u7aef\u5f00\u53d1\u300b\u0f12<br \/>\n\u0f12\u5176\u5b83\u6709\u8da3\u7684\u8ba1\u7b97\u673a\u77e5\u8bc6\u0f12<br \/>\n\u0f3a\u4e16\u4e0a\u672c\u6ca1\u6709\u8def&#xff0c;\u8d70\u7684\u4eba\u591a\u4e86\u81ea\u7136\u5c31\u6709\u4e86\u0f3b \u672c\u7bc7\u6587\u7ae0\u8bb2\u8ff0\u7684\u662fC\u5185\u5b58\u7ba1\u7406\u548c\u6a21\u677f\u7684\u5185\u5bb9&#xff0c;\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9 \u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ee5\u4ee3\u7801\u7684<\/p>\n","protected":false},"author":2,"featured_media":111621,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11653,55,190],"topic":[],"class_list":["post-111622","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-11653","tag-c","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f - \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\/111622.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u0f3a \u4e2a\u4eba\u4e3b\u9875 \u00b7 \u7eaa\u5ff5229 \u0f3b &#x1f3e0;\u6211\u7684\u535a\u5ba2\u4e3b\u9875&#x1f3e0; \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u6570\u636e\u7ed3\u6784\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u7b97\u6cd5\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aC\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aMySQL\u6570\u636e\u5e93\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u524d\u7aef\u5f00\u53d1\u300b\u0f12 \u0f12\u5176\u5b83\u6709\u8da3\u7684\u8ba1\u7b97\u673a\u77e5\u8bc6\u0f12 \u0f3a\u4e16\u4e0a\u672c\u6ca1\u6709\u8def&#xff0c;\u8d70\u7684\u4eba\u591a\u4e86\u81ea\u7136\u5c31\u6709\u4e86\u0f3b \u672c\u7bc7\u6587\u7ae0\u8bb2\u8ff0\u7684\u662fC\u5185\u5b58\u7ba1\u7406\u548c\u6a21\u677f\u7684\u5185\u5bb9&#xff0c;\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9 \u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ee5\u4ee3\u7801\u7684\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/111622.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-01T03:22:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001032253-6abdd20d188c6.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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111622.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/111622.html\",\"name\":\"C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-01T03:22:54+00:00\",\"dateModified\":\"2026-10-01T03:22:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/111622.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/111622.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111622.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f\"}]},{\"@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++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f - \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\/111622.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u0f3a \u4e2a\u4eba\u4e3b\u9875 \u00b7 \u7eaa\u5ff5229 \u0f3b &#x1f3e0;\u6211\u7684\u535a\u5ba2\u4e3b\u9875&#x1f3e0; \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u6570\u636e\u7ed3\u6784\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u7b97\u6cd5\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aC\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300aMySQL\u6570\u636e\u5e93\u300b\u0f12 \u0f12\u4e13\u680f\u76ee\u5f55&#xff1a;\u300a\u524d\u7aef\u5f00\u53d1\u300b\u0f12 \u0f12\u5176\u5b83\u6709\u8da3\u7684\u8ba1\u7b97\u673a\u77e5\u8bc6\u0f12 \u0f3a\u4e16\u4e0a\u672c\u6ca1\u6709\u8def&#xff0c;\u8d70\u7684\u4eba\u591a\u4e86\u81ea\u7136\u5c31\u6709\u4e86\u0f3b \u672c\u7bc7\u6587\u7ae0\u8bb2\u8ff0\u7684\u662fC\u5185\u5b58\u7ba1\u7406\u548c\u6a21\u677f\u7684\u5185\u5bb9&#xff0c;\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9 \u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ee5\u4ee3\u7801\u7684","og_url":"https:\/\/www.wsisp.com\/helps\/111622.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-01T03:22:54+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001032253-6abdd20d188c6.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/111622.html","url":"https:\/\/www.wsisp.com\/helps\/111622.html","name":"C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-01T03:22:54+00:00","dateModified":"2026-10-01T03:22:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/111622.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/111622.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/111622.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u5185\u5b58\u7ba1\u7406 + \u6a21\u677f"}]},{"@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\/111622","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=111622"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/111622\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/111621"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=111622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=111622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=111622"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=111622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}