{"id":40994,"date":"2025-05-30T12:27:15","date_gmt":"2025-05-30T04:27:15","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/40994.html"},"modified":"2025-05-30T12:27:15","modified_gmt":"2025-05-30T04:27:15","slug":"%e3%80%90c%e5%ba%96%e4%b8%81%e8%a7%a3%e7%89%9b%e3%80%91c11-%e7%bb%9f%e4%b8%80%e7%9a%84%e5%88%97%e8%a1%a8%e5%88%9d%e5%a7%8b%e5%8c%96-auto-decltype-nullptr-stl%e4%b8%ad%e4%b8%80%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/40994.html","title":{"rendered":"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11---\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316"},"content":{"rendered":"<p> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042712-683933a0691f2.png\" width=\"20%\" \/> <\/p>\n<p> <font face=\"\u4eff\u5b8b\" color=\"#00FFFF\" size=\"3\"> &#x1f341;\u4f60\u597d&#xff0c;\u6211\u662f RO-BERRY <\/font> <\/p>\n<p> <font face=\"\u4eff\u5b8b\" color=\"bluie\" size=\"3\"> &#x1f4d7; \u81f4\u529b\u4e8eC\u3001C&#043;&#043;\u3001\u6570\u636e\u7ed3\u6784\u3001TCP\/IP\u3001\u6570\u636e\u5e93\u7b49\u7b49\u4e00\u7cfb\u5217\u77e5\u8bc6<\/font> <\/p>\n<p>  <font face=\"\u4eff\u5b8b\" color=\"orange\" size=\"3\"> &#x1f384;\u611f\u8c22\u4f60\u7684\u966a\u4f34\u4e0e\u652f\u6301 &#xff0c;\u6545\u4e8b\u65e2\u6709\u4e86\u5f00\u5934&#xff0c;\u5c31\u8981\u753b\u4e0a\u4e00\u4e2a\u5b8c\u7f8e\u7684\u53e5\u53f7&#xff0c;\u8ba9\u6211\u4eec\u4e00\u8d77\u52a0\u6cb9<\/font> <\/p>\n<hr \/>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042713-683933a150de7.gif\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h4>\u76ee\u5f55<\/h4>\n<ul>\n<li>1. C&#043;&#043;11\u7b80\u4ecb<\/li>\n<li>2. \u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316<\/li>\n<li>\n<ul>\n<li>2.1 &#xff5b;&#xff5d;\u521d\u59cb\u5316<\/li>\n<li>2.2 std::initializer_list<\/li>\n<li>\n<ul>\n<li>std::initializer_list\u7684\u4ecb\u7ecd\u6587\u6863&#xff1a;<\/li>\n<li>**std::initializer_list\u662f\u4ec0\u4e48\u7c7b\u578b&#xff1a;**<\/li>\n<li>std::initializer_list\u7684\u5e94\u7528\u573a\u666f&#xff1a;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>3. \u58f0\u660e<\/li>\n<li>\n<ul>\n<li>3.1 auto<\/li>\n<li>3.2 decltype<\/li>\n<li>3.3 nullptr<\/li>\n<\/ul>\n<\/li>\n<li>4.STL\u4e2d\u4e00\u4e9b\u53d8\u5316<\/li>\n<\/ul>\n<hr \/>\n<h2>1. C&#043;&#043;11\u7b80\u4ecb<\/h2>\n<p>&#x1f341;\u57282003\u5e74C&#043;&#043;\u6807\u51c6\u59d4\u5458\u4f1a\u66fe\u7ecf\u63d0\u4ea4\u4e86\u4e00\u4efd\u6280\u672f\u52d8\u8bef\u8868(\u7b80\u79f0TC1)&#xff0c;\u4f7f\u5f97C&#043;&#043;03\u8fd9\u4e2a\u540d\u5b57\u5df2\u7ecf\u53d6\u4ee3\u4e86C&#043;&#043;98\u79f0\u4e3aC&#043;&#043;11\u4e4b\u524d\u7684\u6700\u65b0C&#043;&#043;\u6807\u51c6\u540d\u79f0\u3002<\/p>\n<p>&#x1f341;\u4e0d\u8fc7\u7531\u4e8eC&#043;&#043;03(TC1)\u4e3b\u8981\u662f\u5bf9C&#043;&#043;98\u6807\u51c6\u4e2d\u7684\u6f0f\u6d1e\u8fdb\u884c\u4fee\u590d&#xff0c;\u8bed\u8a00\u7684\u6838\u5fc3\u90e8\u5206\u5219\u6ca1\u6709\u6539\u52a8&#xff0c;\u56e0\u6b64\u4eba\u4eec\u4e60\u60ef\u6027\u7684\u628a\u4e24\u4e2a\u6807\u51c6\u5408\u5e76\u79f0\u4e3aC&#043;&#043;98\/03\u6807\u51c6\u3002<\/p>\n<p>&#x1f384;\u4eceC&#043;&#043;0x\u5230C&#043;&#043;11&#xff0c;C&#043;&#043;\u6807\u51c610\u5e74\u78e8\u4e00\u5251&#xff0c;\u7b2c\u4e8c\u4e2a\u771f\u6b63\u610f\u4e49\u4e0a\u7684\u6807\u51c6\u73ca\u73ca\u6765\u8fdf\u3002\u76f8\u6bd4\u4e8eC&#043;&#043;98\/03&#xff0c;C&#043;&#043;11\u5219\u5e26\u6765\u4e86\u6570\u91cf\u53ef\u89c2\u7684\u53d8\u5316&#xff0c;\u5176\u4e2d\u5305\u542b\u4e86\u7ea6140\u4e2a\u65b0\u7279\u6027&#xff0c;\u4ee5\u53ca\u5bf9C&#043;&#043;03\u6807\u51c6\u4e2d\u7ea6600\u4e2a\u7f3a\u9677\u7684\u4fee\u6b63&#xff0c;\u8fd9\u4f7f\u5f97C&#043;&#043;11\u66f4\u50cf\u662f\u4eceC&#043;&#043;98\/03\u4e2d\u5b55\u80b2\u51fa\u7684\u4e00\u79cd\u65b0\u8bed\u8a00\u3002\u76f8\u6bd4\u8f83\u800c\u8a00&#xff0c;C&#043;&#043;11\u80fd\u66f4\u597d\u5730\u7528\u4e8e\u7cfb\u7edf\u5f00\u53d1\u548c\u5e93\u5f00\u53d1\u3001\u8bed\u6cd5\u66f4\u52a0\u6cdb\u534e\u548c\u7b80\u5355\u5316\u3001\u66f4\u52a0\u7a33\u5b9a\u548c\u5b89\u5168&#xff0c;\u4e0d\u4ec5\u529f\u80fd\u66f4\u5f3a\u5927&#xff0c;\u800c\u4e14\u80fd\u63d0\u5347\u7a0b\u5e8f\u5458\u7684\u5f00\u53d1\u6548\u7387&#xff0c;\u516c\u53f8\u5b9e\u9645\u9879\u76ee\u5f00\u53d1\u4e2d\u4e5f\u7528\u5f97\u6bd4\u8f83\u591a&#xff0c;\u6240\u4ee5\u6211\u4eec\u8981\u4f5c\u4e3a\u4e00\u4e2a\u91cd\u70b9\u53bb\u5b66\u4e60\u3002C&#043;&#043;11\u589e\u52a0\u7684\u8bed\u6cd5\u7279\u6027\u975e\u5e38\u7bc7\u5e45\u975e\u5e38\u591a&#xff0c;\u6211\u4eec\u8fd9\u91cc\u6ca1\u529e\u6cd5\u4e00 \u4e00\u8bb2\u89e3&#xff0c;\u6240\u4ee5\u4e3b\u8981\u8bb2\u89e3\u5b9e\u9645\u4e2d\u6bd4\u8f83\u5b9e\u7528\u7684\u8bed\u6cd5\u3002<\/p>\n<p><font color=\"buile\">C&#043;&#043;11\u662fC&#043;&#043;\u7684\u7b2c\u4e8c\u4e2a\u4e3b\u8981\u7248\u672c&#xff0c;\u4e5f\u662f\u81eaC&#043;&#043;98\u4ee5\u6765\u6700\u91cd\u8981\u7684\u66f4\u65b0\u3002\u5f15\u5165\u4e86\u5927\u91cf\u7684\u66f4\u6539&#xff0c;\u4ee5\u6807\u51c6\u5316\u73b0\u6709\u5b9e\u8df5\u5e76\u6539\u8fdbC&#043;&#043;\u7a0b\u5e8f\u5458\u53ef\u7528\u7684\u62bd\u8c61\u3002 \u57282011\u5e748\u670812\u65e5\u6700\u7ec8\u83b7\u5f97ISO\u6279\u51c6\u4e4b\u524d&#xff0c;\u4f7f\u7528\u4e86\u540d\u79f0\u201cC&#043;&#043;0x\u201d&#xff0c;\u56e0\u4e3a\u5b83\u9884\u8ba1\u5c06\u57282010\u5e74\u4e4b\u524d\u53d1\u5e03\u3002\u4eceC&#043;&#043;03\u5230C&#043;&#043;11\u82b1\u4e868\u5e74\u65f6\u95f4&#xff0c;\u56e0\u6b64\u5b83\u5df2\u6210\u4e3a\u8fc4\u4eca\u4e3a\u6b62\u7248\u672c\u4e4b\u95f4\u6700\u957f\u7684\u95f4\u9694\u3002\u4ece\u90a3\u65f6\u8d77&#xff0c;\u76ee\u524d&#xff0c;C&#043;&#043;\u6bcf3\u5e74\u5b9a\u671f\u66f4\u65b0\u4e00\u6b21\u3002<\/font><\/p>\n<p>\u8bed\u8a00\u7684\u53d1\u5c55\u5c31\u50cf\u662f\u7ec3\u529f\u6253\u602a\u5347\u7ea7\u4e00\u6837&#xff0c;\u4e5f\u662f\u9010\u6b65\u9012\u8fdb&#xff0c;\u7531\u6d45\u5165\u6df1\u7684\u8fc7\u7a0b\u3002\u6211\u4eec\u5148\u6765\u770b\u4e0bC&#043;&#043;\u7684\u5386\u53f2\u7248\u672c<\/p>\n<table>\n<tr>\u7248\u672c\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td>C with classes<\/td>\n<td>\u7c7b\u53ca\u6d3e\u751f\u7c7b\u3001\u516c\u6709\u548c\u79c1\u6709\u6210\u5458\u3001\u7c7b\u7684\u6784\u9020\u548c\u6790\u6784\u3001\u53cb\u5143\u3001\u5185\u8054\u51fd\u6570\u3001\u8d4b\u503c\u8fd0\u7b97\u7b26\u91cd\u8f7d\u7b49<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;1.0<\/td>\n<td>\u6dfb\u52a0\u865a\u51fd\u6570\u6982\u5ff5&#xff0c;\u51fd\u6570\u548c\u8fd0\u7b97\u7b26\u91cd\u8f7d&#xff0c;\u5f15\u7528\u3001\u5e38\u91cf\u7b49<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;2.0<\/td>\n<td>\u66f4\u52a0\u5b8c\u5584\u652f\u6301\u9762\u5411\u5bf9\u8c61&#xff0c;\u65b0\u589e\u4fdd\u62a4\u6210\u5458\u3001\u591a\u91cd\u7ee7\u627f\u3001\u5bf9\u8c61\u7684\u521d\u59cb\u5316\u3001\u62bd\u8c61\u7c7b\u3001\u9759\u6001\u6210\u5458\u4ee5\u53caconst\u6210\u5458\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;3.0<\/td>\n<td>\u8fdb\u4e00\u6b65\u5b8c\u5584&#xff0c;\u5f15\u5165\u6a21\u677f&#xff0c;\u89e3\u51b3\u591a\u91cd\u7ee7\u627f\u4ea7\u751f\u7684\u4e8c\u4e49\u6027\u95ee\u9898\u548c\u76f8\u5e94\u6784\u9020\u548c\u6790\u6784\u7684\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;98<\/td>\n<td>C&#043;&#043;\u6807\u51c6\u7b2c\u4e00\u4e2a\u7248\u672c&#xff0c;\u7edd\u5927\u591a\u6570\u7f16\u8bd1\u5668\u90fd\u652f\u6301&#xff0c;\u5f97\u5230\u4e86\u56fd\u9645\u6807\u51c6\u5316\u7ec4\u7ec7(ISO)\u548c\u7f8e\u56fd\u6807\u51c6\u5316\u534f\u4f1a\u8ba4\u53ef&#xff0c;\u4ee5\u6a21\u677f\u65b9\u5f0f\u91cd\u5199C&#043;&#043;\u6807\u51c6\u5e93&#xff0c;\u5f15\u5165\u4e86STL(\u6807\u51c6\u6a21\u677f\u5e93)<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;03<\/td>\n<td>C&#043;&#043;\u6807\u51c6\u7b2c\u4e8c\u4e2a\u7248\u672c&#xff0c;\u8bed\u8a00\u7279\u6027\u65e0\u5927\u6539\u53d8&#xff0c;\u4e3b\u8981&#xff1a;\u4fee\u8ba2\u9519\u8bef\u3001\u51cf\u5c11\u591a\u5f02\u6027<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;05<\/td>\n<td>C&#043;&#043;\u6807\u51c6\u59d4\u5458\u4f1a\u53d1\u5e03\u4e86\u4e00\u4efd\u8ba1\u6570\u62a5\u544a(Technical Report&#xff0c;TR1)&#xff0c;\u6b63\u5f0f\u66f4\u540dC&#043;&#043;0x&#xff0c;\u5373&#xff1a;\u8ba1\u5212\u5728\u672c\u4e16\u7eaa\u7b2c\u4e00\u4e2a10\u5e74\u7684\u67d0\u4e2a\u65f6\u95f4\u53d1\u5e03<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;11<\/td>\n<td>\u589e\u52a0\u4e86\u8bb8\u591a\u7279\u6027&#xff0c;\u4f7f\u5f97C&#043;&#043;\u66f4\u50cf\u4e00\u79cd\u65b0\u8bed\u8a00&#xff0c;\u6bd4\u5982&#xff1a;\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u57fa\u4e8e\u8303\u56f4for\u5faa\u73af\u3001auto\u5173\u952e\u5b57\u3001\u65b0\u5bb9\u5668\u3001\u5217\u8868\u521d\u59cb\u5316\u3001\u6807\u51c6\u7ebf\u7a0b\u5e93\u7b49<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;14<\/td>\n<td>\u5bf9C&#043;&#043;11\u7684\u6269\u5c55&#xff0c;\u4e3b\u8981\u662f\u4fee\u590dC&#043;&#043;11\u4e2d\u6f0f\u6d1e\u4ee5\u53ca\u6539\u8fdb&#xff0c;\u6bd4\u5982&#xff1a;\u6cdb\u578b\u7684lambda\u8868\u8fbe\u5f0f&#xff0c;auto\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u63a8\u5bfc&#xff0c;\u4e8c\u8fdb\u5236\u5b57\u9762\u5e38\u91cf\u7b49<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;17<\/td>\n<td>\u5728C&#043;&#043;11\u4e0a\u505a\u4e86\u4e00\u4e9b\u5c0f\u5e45\u6539\u8fdb&#xff0c;\u589e\u52a0\u4e8619\u4e2a\u65b0\u7279\u6027&#xff0c;\u6bd4\u5982&#xff1a;static_assert()\u7684\u6587\u672c\u4fe1\u606f\u53ef\u9009&#xff0c;Fold\u8868\u8fbe\u5f0f\u7528\u4e8e\u53ef\u53d8\u7684\u6a21\u677f&#xff0c;if\u548cswitch\u8bed\u53e5\u4e2d\u7684\u521d\u59cb\u5316\u5668\u7b49<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;20<\/td>\n<td>\u81eaC&#043;&#043;11\u4ee5\u6765\u6700\u5927\u7684\u53d1\u884c\u7248&#xff0c;\u5f15\u5165\u4e86\u8bb8\u591a\u65b0\u7684\u7279\u6027&#xff0c;\u6bd4\u5982&#xff1a;\u6a21\u5757(Modules)\u3001\u534f\u7a0b(Coroutines)\u3001\u8303\u56f4(Ranges)\u3001\u6982\u5ff5(Constraints)\u7b49\u91cd\u5927\u7279\u6027&#xff0c;\u8fd8\u6709\u5bf9\u5df2\u6709\u7279\u6027\u7684\u66f4\u65b0&#xff1a;\u6bd4\u5982Lambda\u652f\u6301\u6a21\u677f\u3001\u8303\u56f4for\u652f\u6301\u521d\u59cb\u5316\u7b49<\/td>\n<\/tr>\n<tr>\n<td>C&#043;&#043;23<\/td>\n<td>\u5236\u5b9aing<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>C&#043;&#043;\u8fd8\u5728\u4e0d\u65ad\u7684\u5411\u540e\u53d1\u5c55\u3002\u4f46\u662f&#xff1a;\u73b0\u5728\u516c\u53f8\u4e3b\u6d41\u4f7f\u7528\u8fd8\u662fC&#043;&#043;98\u548cC&#043;&#043;11&#xff0c;\u6240\u6709\u5927\u5bb6\u4e0d\u7528\u8ffd\u6c42\u6700\u65b0&#xff0c;\u91cd\u70b9\u5c06C&#043;&#043;98\u548cC&#043;&#043;11\u638c\u63e1\u597d&#xff0c;\u7b49\u5de5\u4f5c\u540e&#xff0c;\u968f\u7740\u5bf9C&#043;&#043;\u7406\u89e3\u4e0d\u65ad\u52a0\u6df1&#xff0c;\u6709\u65f6\u95f4\u53ef\u4ee5\u53bb\u7422\u78e8\u4e0b\u66f4\u65b0\u7684\u7279\u6027\u3002<\/p>\n<p>\u2728\u5c0f\u6545\u4e8b&#xff1a;<\/p>\n<p>1998\u5e74\u662fC&#043;&#043;\u6807\u51c6\u59d4\u5458\u4f1a\u6210\u7acb\u7684\u7b2c\u4e00\u5e74&#xff0c;\u672c\u6765\u8ba1\u5212\u4ee5\u540e\u6bcf5\u5e74\u89c6\u5b9e\u9645\u9700\u8981\u66f4\u65b0\u4e00\u6b21\u6807\u51c6&#xff0c;C&#043;&#043;\u56fd\u9645\u6807\u51c6\u59d4\u5458\u4f1a\u5728\u7814\u7a76C&#043;&#043; 03\u7684\u4e0b\u4e00\u4e2a\u7248\u672c\u7684\u65f6\u5019&#xff0c;\u4e00\u5f00\u59cb\u8ba1\u5212\u662f2007\u5e74\u53d1\u5e03&#xff0c;\u6240\u4ee5\u6700\u521d\u8fd9\u4e2a\u6807\u51c6\u53ebC&#043;&#043; 07\u3002\u4f46\u662f\u523006\u5e74\u7684\u65f6\u5019&#xff0c;\u5b98\u65b9\u89c9\u5f972007\u5e74\u80af\u5b9a\u5b8c\u4e0d\u6210C&#043;&#043; 07&#xff0c;\u800c\u4e14\u5b98\u65b9\u89c9\u5f972008\u5e74\u53ef\u80fd\u4e5f\u5b8c\u4e0d\u6210\u3002\u6700\u540e\u5e72\u8106\u53ebC&#043;&#043; 0x\u3002x\u7684\u610f\u601d\u662f\u4e0d\u77e5\u9053\u5230\u5e95\u80fd\u572807\u8fd8\u662f08\u8fd8\u662f09\u5e74\u5b8c\u6210\u3002\u7ed3\u679c2010\u5e74\u7684\u65f6\u5019\u4e5f\u6ca1\u5b8c\u6210&#xff0c;\u6700\u540e\u57282011\u5e74\u7ec8\u4e8e\u5b8c\u6210\u4e86C&#043;&#043;\u6807\u51c6\u3002\u6240\u4ee5\u6700\u7ec8\u5b9a\u540d\u4e3aC&#043;&#043;11\u3002<\/p>\n<hr \/>\n<h2>2. \u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316<\/h2>\n<h3>2.1 &#xff5b;&#xff5d;\u521d\u59cb\u5316<\/h3>\n<li>\u5728C&#043;&#043;98\u4e2d&#xff0c;\u6807\u51c6\u5141\u8bb8\u4f7f\u7528\u82b1\u62ec\u53f7{}\u5bf9\u6570\u7ec4\u6216\u8005\u7ed3\u6784\u4f53\u5143\u7d20\u8fdb\u884c\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u503c\u8bbe\u5b9a\u3002\u6bd4\u5982&#xff1a;<\/li>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">Point<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n <span class=\"token keyword\">int<\/span> _x<span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token keyword\">int<\/span> _y<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<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 \/>\n <span class=\"token keyword\">int<\/span> array1<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token keyword\">int<\/span> array2<span class=\"token punctuation\">[<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">0<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n Point p <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span> <span class=\"token punctuation\">}<\/span><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<li>C&#043;&#043;11\u6269\u5927\u4e86\u7528\u5927\u62ec\u53f7\u62ec\u8d77\u7684\u5217\u8868(\u521d\u59cb\u5316\u5217\u8868)\u7684\u4f7f\u7528\u8303\u56f4&#xff0c;\u4f7f\u5176\u53ef\u7528\u4e8e\u6240\u6709\u7684\u5185\u7f6e\u7c7b\u578b\u548c\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u7c7b\u578b&#xff0c;\u4f7f\u7528\u521d\u59cb\u5316\u5217\u8868\u65f6&#xff0c;\u53ef\u6dfb\u52a0\u7b49\u53f7(&#061;)&#xff0c;\u4e5f\u53ef\u4e0d\u6dfb\u52a0\u3002<\/li>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">Point<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n <span class=\"token keyword\">int<\/span> _x<span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token keyword\">int<\/span> _y<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<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 \/>\n <span class=\"token keyword\">int<\/span> x1 <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/\u7ed9x1\u8d4b\u503c\u4e3a1<\/span><br \/>\n <span class=\"token keyword\">int<\/span> x2<span class=\"token punctuation\">{<\/span> <span class=\"token number\">2<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/\u7ed9x2\u8d4b\u503c\u4e3a2<\/span><br \/>\n <span class=\"token keyword\">int<\/span> x3 <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/\u7ed9x3\u8d4b\u503c\u4e3a3<\/span><\/p>\n<p> <span class=\"token keyword\">int<\/span> array<span class=\"token punctuation\">[<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/\u539f\u7248\u672c<\/span><br \/>\n <span class=\"token keyword\">int<\/span> array1<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token keyword\">int<\/span> array2<span class=\"token punctuation\">[<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token number\">0<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p> Point p<span class=\"token punctuation\">{<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n <span class=\"token comment\">\/\/ C&#043;&#043;11\u4e2d\u5217\u8868\u521d\u59cb\u5316\u4e5f\u53ef\u4ee5\u9002\u7528\u4e8enew\u8868\u8fbe\u5f0f\u4e2d<\/span><br \/>\n <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> pa <span class=\"token operator\">&#061;<\/span> new <span class=\"token keyword\">int<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token number\">0<\/span> <span class=\"token punctuation\">}<\/span><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<li>\u521b\u5efa\u5bf9\u8c61\u65f6\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u521d\u59cb\u5316\u65b9\u5f0f\u8c03\u7528\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316<\/li>\n<p>class Date<br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\npublic<span class=\"token operator\">:<\/span><br \/>\n<span class=\"token function\">Date<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> year<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> month<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> day<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">:<\/span><span class=\"token function\">_year<\/span><span class=\"token punctuation\">(<\/span>year<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">,<\/span> <span class=\"token function\">_month<\/span><span class=\"token punctuation\">(<\/span>month<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">,<\/span> <span class=\"token function\">_day<\/span><span class=\"token punctuation\">(<\/span>day<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;Date(int year, int month, int day)&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\nprivate<span class=\"token operator\">:<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _year<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _month<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _day<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<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 \/>\nDate <span class=\"token function\">d1<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2024<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u539f\u7248\u672cC&#043;&#043;98\u7684\u6784\u9020<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u4ee5\u4e0b\u662fC&#043;&#043;11\u652f\u6301\u7684\u5217\u8868\u521d\u59cb\u5316&#xff0c;\u8fd9\u91cc\u4f1a\u8c03\u7528\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316<\/span><br \/>\nDate d2<span class=\"token punctuation\">{<\/span> <span class=\"token number\">2024<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\nDate d3 <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">2024<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span> <span class=\"token punctuation\">}<\/span><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>\u8fd9\u4e09\u79cd\u5217\u8868\u521d\u59cb\u5316\u90fd\u53ef\u4ee5\u8fdb\u884c\u652f\u6301<\/p>\n<p>\u603b\u4e4bC&#043;&#043;11\u7684\u7279\u6027\u5c31\u662f\u4e00\u5207\u7686\u53ef\u7528{ }\u521d\u59cb\u5316<\/p>\n<hr \/>\n<h3>2.2 std::initializer_list<\/h3>\n<p>&#x1f384;Date\u7c7b\u578b\u7684\u5b9e\u4f8b\u6784\u9020\u5c31\u662f\u8c03\u7528\u5176\u5185\u90e8\u7684\u6784\u9020\u51fd\u6570 &#x1f384;vector\u5bb9\u5668\u7684\u5b9e\u4f8b\u6784\u9020\u5219\u662f\u4f7f\u7528\u4e86initializer_list<\/p>\n<p><font color=\"red\">\u4ed6\u4eec\u90fd\u662f\u8fdb\u884c\u4e86\u6784\u9020&#xff0c;\u4f46\u662fDate\u8c03\u7528\u62f7\u8d1d\u6784\u9020\u9700\u8981\u6309\u7167\u6784\u9020\u51fd\u6570\u4f20\u5165\u4e09\u4e2a\u53c2\u6570&#xff0c;vector\u53ef\u4ee5\u4f20\u5165\u65e0\u6570\u4e2a\u53c2\u6570&#xff0c;\u56e0\u4e3avector\u8c03\u7528\u7684\u662finitializer_list\u7684\u6784\u9020<\/font><\/p>\n<p><span class=\"token comment\">\/\/\u6211\u4eec\u7ecf\u5e38\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u521d\u59cb\u5316vector<\/span><br \/>\nvector<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">&gt;<\/span> v <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/\u8fd9\u91cc\u53f3\u8fb9\u5176\u5b9e\u5c31\u662f\u4f7f\u7528\u4e86initializer_list<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042713-683933a1797c4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h4>std::initializer_list\u7684\u4ecb\u7ecd\u6587\u6863&#xff1a;<\/h4>\n<p>http:\/\/www.cplusplus.com\/reference\/initializer_list\/initializer_list\/<\/p>\n<hr \/>\n<h4>std::initializer_list\u662f\u4ec0\u4e48\u7c7b\u578b&#xff1a;<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042713-683933a19dc98.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230initializer_list\u5176\u5b9e\u662f\u4e00\u4e2a\u6a21\u7248&#xff0c;\u6211\u4eec\u4f20\u5165\u4ec0\u4e48\u7c7b\u578b\u7684\u6570\u636e\u4ed6\u5c31\u4f1a\u662f\u4ec0\u4e48\u6837\u7684\u7c7b\u578b<\/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 \/>\n<span class=\"token comment\">\/\/ the type of il is an initializer_list <\/span><br \/>\n<span class=\"token keyword\">auto<\/span> il <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">20<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">30<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\ninitializer_list<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">&gt;<\/span> il2 <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">1<\/span> <span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span>  <span class=\"token punctuation\">,<\/span><span class=\"token number\">3<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/\u8fd9\u4e24\u4e2a\u521d\u59cb\u5316\u662f\u4e00\u6837\u7684<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>il<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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 keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042713-683933a1cca6a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/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 \/>\n<span class=\"token comment\">\/\/ the type of il is an initializer_list <\/span><br \/>\n<span class=\"token keyword\">auto<\/span> il <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">1.1<\/span> <span class=\"token punctuation\">,<\/span><span class=\"token number\">1.2<\/span>  <span class=\"token punctuation\">,<\/span><span class=\"token number\">1.3<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>il<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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 keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042713-683933a1e6c39.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<p>&#x1f341;\u53ef\u4ee5\u7406\u89e3\u4e3ainitializer_list\u4e3aC&#043;&#043;11\u65b0\u589e\u7684\u4e00\u4e2a\u5bb9\u5668&#xff0c;\u4f46\u662f\u8fd9\u4e2a\u5bb9\u5668\u548c\u6211\u4eec\u4ee5\u524d\u8bb2\u8ff0\u7684\u5bb9\u5668\u4e0d\u4e00\u6837&#xff0c;\u8fd9\u4e2a\u5bb9\u5668\u4e0d\u5b9e\u9645\u5b58\u50a8\u6570\u636e<\/p>\n<li>\u4f46\u8bf7\u6ce8\u610f&#xff0c;\u8be5\u6a21\u677f\u7c7b\u4e0d\u662f\u9690\u5f0f\u5b9a\u4e49\u7684&#xff0c;\u5373\u4f7f\u9690\u5f0f\u4f7f\u7528\u4e86\u7c7b\u578b&#xff0c;\u4e5f\u5e94\u5305\u62ec\u5934&#xff1c;initializer_list&#xff1e;\u6765\u8bbf\u95ee\u5b83\u3002<\/li>\n<li>initializer_list\u5bf9\u8c61\u662f\u81ea\u52a8\u6784\u5efa\u7684&#xff0c;\u5c31\u597d\u50cf\u5206\u914d\u4e86\u4e00\u4e2aT\u7c7b\u578b\u7684\u5143\u7d20\u6570\u7ec4\u4e00\u6837&#xff0c;\u4f7f\u7528\u4efb\u4f55\u5fc5\u8981\u7684\u975e\u6536\u7f29\u9690\u5f0f\u8f6c\u6362&#xff0c;\u5c06\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u590d\u5236\u521d\u59cb\u5316\u4e3a\u6570\u7ec4\u4e2d\u7684\u76f8\u5e94\u5143\u7d20\u3002<\/li>\n<li>initializer_list\u5bf9\u8c61\u5f15\u7528\u8be5\u6570\u7ec4\u7684\u5143\u7d20\u800c\u4e0d\u5305\u542b\u8fd9\u4e9b\u5143\u7d20&#xff1a;\u590d\u5236initializer_list\u5bf9\u8c61\u4f1a\u751f\u6210\u53e6\u4e00\u4e2a\u5f15\u7528\u76f8\u540c\u5e95\u5c42\u5143\u7d20\u7684\u5bf9\u8c61&#xff0c;\u800c\u4e0d\u662f\u5f15\u7528\u5b83\u4eec\u7684\u65b0\u526f\u672c&#xff08;\u5f15\u7528\u8bed\u4e49&#xff09;\u3002<\/li>\n<li>\u6b64\u4e34\u65f6\u6570\u7ec4\u7684\u751f\u5b58\u671f\u4e0einitializer_list\u5bf9\u8c61\u7684\u751f\u5b58\u671f\u76f8\u540c\u3002<\/li>\n<hr \/>\n<h4>std::initializer_list\u7684\u5e94\u7528\u573a\u666f&#xff1a;<\/h4>\n<li>\u521d\u59cb\u5316\u5bb9\u5668&#xff1a;std::initializer_list\u7528\u4e8e\u521d\u59cb\u5316\u5404\u79cd\u5bb9\u5668&#xff0c;\u5982std::vector\u3001std::list\u3001std::set\u7b49\u3002\u901a\u8fc7\u4f7f\u7528\u82b1\u62ec\u53f7{}\u6765\u521b\u5efa\u4e00\u4e2astd::initializer_list\u5bf9\u8c61&#xff0c;\u5e76\u5c06\u5176\u4f5c\u4e3a\u5bb9\u5668\u7684\u6784\u9020\u51fd\u6570\u53c2\u6570&#xff0c;\u53ef\u4ee5\u65b9\u4fbf\u5730\u521d\u59cb\u5316\u5bb9\u5668\u4e2d\u7684\u5143\u7d20\u3002<\/li>\n<p>\u5177\u4f53\u53ef\u4ee5\u770b\u6587\u6863&#xff1a;<\/p>\n<p>http:\/\/www.cplusplus.com\/reference\/list\/list\/list\/ http:\/\/www.cplusplus.com\/reference\/vector\/vector\/vector\/ http:\/\/www.cplusplus.com\/reference\/map\/map\/map\/ http:\/\/www.cplusplus.com\/reference\/vector\/vector\/operator&#061;\/<\/p>\n<li>\n<p>\u51fd\u6570\u53c2\u6570&#xff1a;std::initializer_list\u53ef\u4ee5\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570&#xff0c;\u7528\u4e8e\u63a5\u6536\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\u3002\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f20\u9012\u4e00\u7ec4\u503c\u7ed9\u51fd\u6570&#xff0c;\u5e76\u5728\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u5904\u7406\u3002\u4f8b\u5982&#xff0c;\u53ef\u4ee5\u4f7f\u7528std::initializer_list\u6765\u5b9e\u73b0\u4e00\u4e2a\u53ef\u53d8\u53c2\u6570\u7684\u6253\u5370\u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u81ea\u5b9a\u4e49\u5bf9\u8c61&#xff1a;\u5982\u679c\u4e00\u4e2a\u7c7b\u5177\u6709\u63a5\u53d7std::initializer_list\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570&#xff0c;\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528\u82b1\u62ec\u53f7{}\u6765\u521d\u59cb\u5316\u8be5\u7c7b\u7684\u5bf9\u8c61\u3002\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u4e3a\u81ea\u5b9a\u4e49\u5bf9\u8c61\u63d0\u4f9b\u4e00\u7ec4\u521d\u59cb\u503c\u3002<\/p>\n<\/li>\n<hr \/>\n<h2>3. \u58f0\u660e<\/h2>\n<p>c&#043;&#043;11\u63d0\u4f9b\u4e86\u591a\u79cd\u7b80\u5316\u58f0\u660e\u7684\u65b9\u5f0f&#xff0c;\u5c24\u5176\u662f\u5728\u4f7f\u7528\u6a21\u677f\u65f6\u3002<\/p>\n<h3>3.1 auto<\/h3>\n<p>&#x1f636;\u5728C&#043;&#043;98\u4e2dauto\u662f\u4e00\u4e2a\u5b58\u50a8\u7c7b\u578b\u7684\u8bf4\u660e\u7b26&#xff0c;\u8868\u660e\u53d8\u91cf\u662f\u5c40\u90e8\u81ea\u52a8\u5b58\u50a8\u7c7b\u578b&#xff0c;\u4f46\u662f\u5c40\u90e8\u57df\u4e2d\u5b9a\u4e49\u5c40\u90e8\u7684\u53d8\u91cf\u9ed8\u8ba4\u5c31\u662f\u81ea\u52a8\u5b58\u50a8\u7c7b\u578b&#xff0c;\u6240\u4ee5auto\u5c31\u6ca1\u4ec0\u4e48\u4ef7\u503c\u4e86\u3002<\/p>\n<p>&#x1f636;C&#043;&#043;11\u4e2d\u5e9f\u5f03auto\u539f\u6765\u7684\u7528\u6cd5&#xff0c;\u5c06\u5176\u7528\u4e8e\u5b9e\u73b0\u81ea\u52a8\u7c7b\u578b\u63a8\u65ad\u3002\u8fd9\u6837\u8981\u6c42\u5fc5\u987b\u8fdb\u884c\u663e\u793a\u521d\u59cb\u5316&#xff0c;\u8ba9\u7f16\u8bd1\u5668\u5c06\u5b9a\u4e49\u5bf9\u8c61\u7684\u7c7b\u578b\u8bbe\u7f6e\u4e3a\u521d\u59cb\u5316\u503c\u7684\u7c7b\u578b\u3002<\/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 \/>\n<span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> p <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>i<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> pf <span class=\"token operator\">&#061;<\/span> strcpy<span class=\"token punctuation\">;<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>p<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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 \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>pf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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 \/>\nmap<span class=\"token operator\">&lt;<\/span>string<span class=\"token punctuation\">,<\/span> string<span class=\"token operator\">&gt;<\/span> dict <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;sort&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u6392\u5e8f&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;insert&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u63d2\u5165&#034;<\/span><span class=\"token punctuation\">}<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/map&lt;string, string&gt;::iterator it &#061; dict.begin();<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> it <span class=\"token operator\">&#061;<\/span> dict<span class=\"token punctuation\">.<\/span><span class=\"token function\">begin<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><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><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042714-683933a216e46.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h3>3.2 decltype<\/h3>\n<p>&#x1f341;decltype\u662fC&#043;&#043;11\u5f15\u5165\u7684\u4e00\u4e2a\u5173\u952e\u5b57&#xff0c;\u7528\u4e8e\u83b7\u53d6\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b\u3002\u5b83\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u63a8\u5bfc\u51fa\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b&#xff0c;\u5e76\u5c06\u5176\u4f5c\u4e3a\u8fd4\u56de\u503c\u7c7b\u578b\u6216\u53d8\u91cf\u7684\u7c7b\u578b\u3002decltype\u7684\u8bed\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p>decltype(expression)<\/p>\n<p>&#x1f384;\u5176\u4e2d&#xff0c;expression\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f&#xff0c;\u53ef\u4ee5\u662f\u53d8\u91cf\u3001\u51fd\u6570\u8c03\u7528\u3001\u8fd0\u7b97\u7b26\u7b49\u3002 \u4f7f\u7528decltype\u53ef\u4ee5\u65b9\u4fbf\u5730\u83b7\u53d6\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b&#xff0c;\u7279\u522b\u662f\u5728\u6a21\u677f\u7f16\u7a0b\u4e2d\u975e\u5e38\u6709\u7528\u3002\u5b83\u53ef\u4ee5\u907f\u514d\u624b\u52a8\u6307\u5b9a\u7c7b\u578b&#xff0c;\u51cf\u5c11\u4ee3\u7801\u5197\u4f59\u548c\u9519\u8bef\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u5047\u8bbe\u6709\u4e00\u4e2a\u53d8\u91cfx&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528decltype\u6765\u83b7\u53d6x\u7684\u7c7b\u578b&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">decltype<\/span><span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">)<\/span> y<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ y\u7684\u7c7b\u578b\u4e3aint<\/span><\/p>\n<p>\u53e6\u5916&#xff0c;decltype\u8fd8\u53ef\u4ee5\u7528\u4e8e\u63a8\u5bfc\u51fd\u6570\u8fd4\u56de\u503c\u7c7b\u578b&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>int foo(); decltype(foo()) result; \/\/ result\u7684\u7c7b\u578b\u4e3aint<\/p>\n<p>\u603b\u7ed3\u4e00\u4e0b&#xff0c;decltype\u662fC&#043;&#043;11\u5f15\u5165\u7684\u5173\u952e\u5b57&#xff0c;\u7528\u4e8e\u83b7\u53d6\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b\u3002\u5b83\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u63a8\u5bfc\u51fa\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b&#xff0c;\u5e76\u5c06\u5176\u4f5c\u4e3a\u8fd4\u56de\u503c\u7c7b\u578b\u6216\u53d8\u91cf\u7684\u7c7b\u578b\u3002<\/p>\n<p>template<span class=\"token operator\">&lt;<\/span>class T1<span class=\"token punctuation\">,<\/span> class T2<span class=\"token operator\">&gt;<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">F<\/span><span class=\"token punctuation\">(<\/span>T1 t1<span class=\"token punctuation\">,<\/span> T2 t2<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token function\">decltype<\/span><span class=\"token punctuation\">(<\/span>t1 <span class=\"token operator\">*<\/span> t2<span class=\"token punctuation\">)<\/span> ret<span class=\"token punctuation\">;<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>ret<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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\">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 \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> y <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2.2<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token function\">decltype<\/span><span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">)<\/span> z <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ ret\u7684\u7c7b\u578b\u662fint<\/span><br \/>\n<span class=\"token function\">decltype<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">*<\/span> y<span class=\"token punctuation\">)<\/span> ret<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ ret\u7684\u7c7b\u578b\u662fdouble<\/span><br \/>\n<span class=\"token function\">decltype<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>x<span class=\"token punctuation\">)<\/span> p<span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ p\u7684\u7c7b\u578b\u662fint*<\/span><\/p>\n<p>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>z<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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 \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>ret<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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 \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token function\">typeid<\/span><span class=\"token punctuation\">(<\/span>p<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/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 function\">F<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token char\">&#039;a&#039;<\/span><span class=\"token punctuation\">)<\/span><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><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042714-683933a242e8f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u6ce8\u610f&#xff1a;<\/p>\n<p>const \u4fee\u9970int\u3001double\u7b49\u7c7b\u578b\u5728\u4f7f\u7528decltype\u540econst\u4f1a\u6d88\u5931 const \u4fee\u9970\u6307\u9488\u65f6\u4f7f\u7528decltype\u540econst\u4f1a\u4f9d\u65e7\u5b58\u5728<\/p>\n<hr \/>\n<h3>3.3 nullptr<\/h3>\n<p>&#x1f341;\u5728C&#043;&#043;\u4e2d&#xff0c;nullptr\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u5173\u952e\u5b57&#xff0c;\u7528\u4e8e\u8868\u793a\u7a7a\u6307\u9488\u3002\u5b83\u7684\u8bbe\u8ba1\u610f\u4e49\u5728\u4e8e\u89e3\u51b3\u4e86C\u8bed\u8a00\u4e2dNULL\u7684\u4e00\u4e9b\u95ee\u9898\u3002<\/p>\n<li>\n<p>\u9996\u5148&#xff0c;nullptr\u7684\u5f15\u5165\u6d88\u9664\u4e86C\u8bed\u8a00\u4e2dNULL\u7684\u4e8c\u4e49\u6027\u3002\u5728C\u8bed\u8a00\u4e2d&#xff0c;NULL\u88ab\u5b9a\u4e49\u4e3a0&#xff0c;\u4f460\u4e5f\u53ef\u4ee5\u8868\u793a\u6574\u6570\u7684\u96f6\u503c\u3002\u8fd9\u5c31\u5bfc\u81f4\u4e86\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b&#xff0c;\u7f16\u8bd1\u5668\u65e0\u6cd5\u786e\u5b9aNULL\u5230\u5e95\u662f\u6307\u9488\u7c7b\u578b\u8fd8\u662f\u6574\u6570\u7c7b\u578b\u3002\u800cnullptr\u5219\u660e\u786e\u8868\u793a\u4e00\u4e2a\u7a7a\u6307\u9488&#xff0c;\u6d88\u9664\u4e86\u8fd9\u79cd\u4e8c\u4e49\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>\u5176\u6b21&#xff0c;nullptr\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u5b89\u5168\u6027\u3002\u4f7f\u7528nullptr\u53ef\u4ee5\u660e\u786e\u5730\u8868\u793a\u4e00\u4e2a\u7a7a\u6307\u9488&#xff0c;\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u6613\u61c2\u3002\u540c\u65f6&#xff0c;\u4f7f\u7528nullptr\u8fd8\u53ef\u4ee5\u907f\u514d\u4e00\u4e9b\u6f5c\u5728\u7684\u9519\u8bef&#xff0c;\u6bd4\u5982\u5c06\u6574\u6570\u503c\u9519\u8bef\u5730\u8d4b\u7ed9\u6307\u9488\u53d8\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p>\u6700\u540e&#xff0c;nullptr\u8fd8\u53ef\u4ee5\u4e0e\u51fd\u6570\u91cd\u8f7d\u4e00\u8d77\u4f7f\u7528&#xff0c;\u7528\u4e8e\u533a\u5206\u4e0d\u540c\u7684\u51fd\u6570\u91cd\u8f7d\u3002\u5728C&#043;&#043;\u4e2d&#xff0c;\u51fd\u6570\u91cd\u8f7d\u662f\u6307\u5728\u540c\u4e00\u4e2a\u4f5c\u7528\u57df\u5185\u5b9a\u4e49\u591a\u4e2a\u540c\u540d\u51fd\u6570&#xff0c;\u4f46\u5b83\u4eec\u7684\u53c2\u6570\u7c7b\u578b\u6216\u53c2\u6570\u4e2a\u6570\u4e0d\u540c\u3002\u5f53\u6211\u4eec\u8c03\u7528\u8fd9\u4e9b\u91cd\u8f7d\u51fd\u6570\u65f6&#xff0c;\u5982\u679c\u4f20\u5165\u4e00\u4e2a\u7a7a\u6307\u9488\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u7f16\u8bd1\u5668\u53ef\u4ee5\u6839\u636enullptr\u7684\u7c7b\u578b\u6765\u786e\u5b9a\u8c03\u7528\u54ea\u4e2a\u91cd\u8f7d\u51fd\u6570\u3002<\/p>\n<\/li>\n<p>\u603b\u7ed3\u4e00\u4e0b&#xff0c;nullptr\u5728C&#043;&#043;\u4e2d\u7684\u8bbe\u8ba1\u610f\u4e49\u4e3b\u8981\u6709\u4e09\u70b9&#xff1a;\u6d88\u9664NULL\u7684\u4e8c\u4e49\u6027\u3001\u63d0\u9ad8\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u5b89\u5168\u6027\u3001\u4e0e\u51fd\u6570\u91cd\u8f7d\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<p>\u7531\u4e8eC&#043;&#043;\u4e2dNULL\u88ab\u5b9a\u4e49\u6210\u5b57\u9762\u91cf0&#xff0c;\u8fd9\u6837\u5c31\u53ef\u80fd\u56de\u5e26\u6765\u4e00\u4e9b\u95ee\u9898&#xff0c;\u56e0\u4e3a0\u65e2\u80fd\u6307\u9488\u5e38\u91cf&#xff0c;\u53c8\u80fd\u8868\u793a\u6574\u5f62\u5e38\u91cf\u3002\u6240\u4ee5\u51fa\u4e8e\u6e05\u6670\u548c\u5b89\u5168\u7684\u89d2\u5ea6\u8003\u8651&#xff0c;C&#043;&#043;11\u4e2d\u65b0\u589e\u4e86nullptr&#xff0c;\u7528\u4e8e\u8868\u793a\u7a7a\u6307\u9488\u3002<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">ifndef<\/span> <span class=\"token expression\"><span class=\"token constant\">NULL<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">ifdef<\/span> <span class=\"token expression\">__cplusplus<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">NULL<\/span>   <span class=\"token expression\"><span class=\"token number\">0<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">else<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">NULL<\/span>   <span class=\"token expression\"><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">void<\/span> <span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">endif<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">endif<\/span><\/span><\/p>\n<hr \/>\n<h2>4.STL\u4e2d\u4e00\u4e9b\u53d8\u5316<\/h2>\n<p>\u65b0\u5bb9\u5668 \u7528\u6a58\u8272\u5708\u8d77\u6765\u662fC&#043;&#043;11\u4e2d\u7684\u4e00\u4e9b\u51e0\u4e2a\u65b0\u5bb9\u5668&#xff0c;\u4f46\u662f\u5b9e\u9645\u6700\u6709\u7528\u7684\u662funordered_map\u548cunordered_set\u3002\u8fd9\u4e24\u4e2a\u6211\u4eec\u524d\u9762\u5df2\u7ecf\u8fdb\u884c\u4e86\u975e\u5e38\u8be6\u7ec6\u7684\u8bb2\u89e3&#xff0c;\u5176\u4ed6\u7684\u5927\u5bb6\u4e86\u89e3\u4e00\u4e0b\u5373\u53ef\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042714-683933a26b904.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u5bb9\u5668\u4e2d\u7684\u4e00\u4e9b\u65b0\u65b9\u6cd5<\/p>\n<ul>\n<li>\u5982\u679c\u6211\u4eec\u518d\u7ec6\u7ec6\u53bb\u770b\u4f1a\u53d1\u73b0\u57fa\u672c\u6bcf\u4e2a\u5bb9\u5668\u4e2d\u90fd\u589e\u52a0\u4e86\u4e00\u4e9bC&#043;&#043;11\u7684\u65b9\u6cd5&#xff0c;\u4f46\u662f\u5176\u5b9e\u5f88\u591a\u90fd\u662f\u7528\u5f97 \u6bd4\u8f83\u5c11\u7684\u3002<\/li>\n<li>\u6bd4\u5982\u63d0\u4f9b\u4e86cbegin\u548ccend\u65b9\u6cd5\u8fd4\u56deconst\u8fed\u4ee3\u5668\u7b49\u7b49&#xff0c;\u4f46\u662f\u5b9e\u9645\u610f\u4e49\u4e0d\u5927&#xff0c;\u56e0\u4e3abegin\u548cend\u4e5f\u662f \u53ef\u4ee5\u8fd4\u56deconst\u8fed\u4ee3\u5668\u7684&#xff0c;\u8fd9\u4e9b\u90fd\u662f\u5c5e\u4e8e\u9526\u4e0a\u6dfb\u82b1\u7684\u64cd\u4f5c\u3002<\/li>\n<li>\u5b9e\u9645\u4e0aC&#043;&#043;11\u66f4\u65b0\u540e&#xff0c;\u5bb9\u5668\u4e2d\u589e\u52a0\u7684\u65b0\u65b9\u6cd5\u6700\u540e\u7528\u7684\u63d2\u5165\u63a5\u53e3\u51fd\u6570\u7684\u53f3\u503c\u5f15\u7528\u7248\u672c&#xff1a;<\/li>\n<\/ul>\n<p>http:\/\/www.cplusplus.com\/reference\/vector\/vector\/emplace_back\/ http:\/\/www.cplusplus.com\/reference\/vector\/vector\/push_back\/ http:\/\/www.cplusplus.com\/reference\/map\/map\/insert\/ http:\/\/www.cplusplus.com\/reference\/map\/map\/emplace\/<\/p>\n<p>\u4f46\u662f\u8fd9\u4e9b\u63a5\u53e3\u5230\u5e95\u610f\u4e49\u5728\u54ea&#xff1f;\u7f51\u4e0a\u90fd\u8bf4\u4ed6\u4eec\u80fd\u63d0\u9ad8\u6548\u7387&#xff0c;\u4ed6\u4eec\u662f\u5982\u4f55\u63d0\u9ad8\u6548\u7387\u7684&#xff1f; \u8bf7\u770b\u4e0b\u9762\u7684\u53f3\u503c\u5f15\u7528\u548c\u79fb\u52a8\u8bed\u4e49\u7ae0\u8282\u7684\u8bb2\u89e3\u3002\u53e6\u5916emplace\u8fd8\u6d89\u53ca\u6a21\u677f\u7684\u53ef\u53d8\u53c2\u6570&#xff0c;\u4e5f\u9700\u8981\u518d\u7ee7 \u7eed\u6df1\u5165\u5b66\u4e60\u540e\u9762\u7ae0\u8282\u7684\u77e5\u8bc6\u3002<\/p>\n<p>\u603b\u7ed3&#xff1a; STL\u7684\u4e00\u4e9b\u53d8\u5316&#xff1a;<\/p>\n<li>\u65b0\u5bb9\u5668<\/li>\n<li>unerdered_xxx \u7528\u5904\u5f88\u5927<\/li>\n<li>array\/forward_list \u7528\u5904\u76f8\u89c1\u4e00\u822c<\/li>\n<li>\u65b0\u63a5\u53e3<\/li>\n<li>\u65e0\u5173\u75db\u75d2\u7684\u63a5\u53e3\u2013cbegin\u7b49<\/li>\n<li>initializer_list\u7cfb\u5217\u7684\u6784\u9020(\u91cd\u8981)<\/li>\n<li>push_xxx\/insert\/emplace\u7b49\u589e\u52a0\u4f18\u8d28\u5e94\u7528\u63d2\u5165\u7248\u672c\u610f\u4e49\u91cd\u5927&#xff0c;\u63d0\u9ad8\u6548\u7387<\/li>\n<li>\u5bb9\u5668\u65b0\u589e\u79fb\u52a8\u6784\u9020\u548c\u79fb\u52a8\u8d4b\u503c&#xff0c;\u4e5f\u53ef\u4ee5\u51cf\u5c11\u62f7\u8d1d&#xff0c;\u63d0\u9ad8\u6548\u7387<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.7k\u6b21\uff0c\u70b9\u8d5e72\u6b21\uff0c\u6536\u85cf69\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86C++11\u7684\u4e3b\u8981\u7279\u6027\uff0c\u5982\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316\u3001std::initializer_list\u7684\u4f5c\u7528\u3001auto\u548cdecltype\u7684\u5173\u952e\u5b57\u4ee5\u53canullptr\u7684\u5f15\u5165\uff0c\u540c\u65f6\u63d0\u5230\u4e86STL\u4e2d\u65b0\u589e\u7684\u5bb9\u5668\u548c\u63a5\u53e3\uff0c\u91cd\u70b9\u5f3a\u8c03\u4e86\u79fb\u52a8\u8bed\u4e49\u5bf9\u6548\u7387\u63d0\u5347\u7684\u91cd\u8981\u6027\u3002<\/p>\n","protected":false},"author":2,"featured_media":40985,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,3758,99,426],"topic":[],"class_list":{"0":"post-40994","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-server","8":"tag-c","10":"tag-java","11":"tag-jvm"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11-\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316 - \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\/40994.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11-\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.7k\u6b21\uff0c\u70b9\u8d5e72\u6b21\uff0c\u6536\u85cf69\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86C++11\u7684\u4e3b\u8981\u7279\u6027\uff0c\u5982\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316\u3001std::initializer_list\u7684\u4f5c\u7528\u3001auto\u548cdecltype\u7684\u5173\u952e\u5b57\u4ee5\u53canullptr\u7684\u5f15\u5165\uff0c\u540c\u65f6\u63d0\u5230\u4e86STL\u4e2d\u65b0\u589e\u7684\u5bb9\u5668\u548c\u63a5\u53e3\uff0c\u91cd\u70b9\u5f3a\u8c03\u4e86\u79fb\u52a8\u8bed\u4e49\u5bf9\u6548\u7387\u63d0\u5347\u7684\u91cd\u8981\u6027\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/40994.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-30T04:27:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042712-683933a0691f2.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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40994.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/40994.html\",\"name\":\"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11-\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-30T04:27:15+00:00\",\"dateModified\":\"2025-05-30T04:27:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/40994.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/40994.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40994.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11---\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316\"}]},{\"@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":"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11-\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316 - \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\/40994.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11-\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.7k\u6b21\uff0c\u70b9\u8d5e72\u6b21\uff0c\u6536\u85cf69\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86C++11\u7684\u4e3b\u8981\u7279\u6027\uff0c\u5982\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316\u3001std::initializer_list\u7684\u4f5c\u7528\u3001auto\u548cdecltype\u7684\u5173\u952e\u5b57\u4ee5\u53canullptr\u7684\u5f15\u5165\uff0c\u540c\u65f6\u63d0\u5230\u4e86STL\u4e2d\u65b0\u589e\u7684\u5bb9\u5668\u548c\u63a5\u53e3\uff0c\u91cd\u70b9\u5f3a\u8c03\u4e86\u79fb\u52a8\u8bed\u4e49\u5bf9\u6548\u7387\u63d0\u5347\u7684\u91cd\u8981\u6027\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/40994.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-30T04:27:15+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042712-683933a0691f2.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/40994.html","url":"https:\/\/www.wsisp.com\/helps\/40994.html","name":"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11-\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-30T04:27:15+00:00","dateModified":"2025-05-30T04:27:15+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/40994.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/40994.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/40994.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++\u5e96\u4e01\u89e3\u725b\u3011C++11---\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316 | auto | decltype | nullptr | STL\u4e2d\u4e00\u4e9b\u53d8\u5316"}]},{"@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\/40994","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=40994"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40994\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/40985"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=40994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=40994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=40994"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=40994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}