{"id":169,"date":"2025-07-15T18:39:41","date_gmt":"2025-07-15T10:39:41","guid":{"rendered":"http:\/\/www.tgwttt.xyz\/?p=169"},"modified":"2025-11-24T16:41:22","modified_gmt":"2025-11-24T08:41:22","slug":"c11%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%881%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.tgwttt.xyz\/?p=169","title":{"rendered":"c++11\u65b0\u7279\u6027\uff081\uff09"},"content":{"rendered":"\n<p>                C++11 \u662f C++ \u7684\u7b2c\u2f06\u4e2a\u4e3b\u8981\u7248\u672c\uff0c\u5e76\u4e14\u662f\u4ece C++98 \u8d77\u7684\u6700\u91cd\u8981\u66f4\u65b0\u3002\u5b83\u5f15\u2f0a\u4e86\u2f24\u91cf\u66f4\u6539\uff0c\u6807\u51c6\u5316\u4e86\u65e2\u6709\u5b9e\u8df5\uff0c\u5e76\u6539\u8fdb\u4e86\u5bf9 C++ \u7a0b\u5e8f\u5458\u53ef\u2f64\u7684\u62bd\u8c61\u3002\u5728\u5b83\u6700\u7ec8\u7531 ISO \u5728 2011 \u5e74 8 \u2f49 12 \u2f47\u91c7\u7eb3\u524d\uff0c\u2f08\u4eec\u66fe\u4f7f\u2f64\u540d\u79f0\u201cC++0x\u201d\uff0c\u56e0\u4e3a\u5b83\u66fe\u88ab\u671f\u5f85\u5728 2010 \u5e74\u4e4b\u524d\u53d1\u5e03\u3002C++03 \u4e0e C++11 \u671f\u95f4\u82b1\u4e86 8 \u5e74\u65f6\u95f4\uff0c\u6545\u2f7d\u8fd9\u662f\u8fc4\u4eca\u4e3a\u2f4c\u6700\u2ed3\u7684\u7248\u672c\u95f4\u9694\u3002\u4ece\u90a3\u65f6\u8d77\uff0cC++ \u6709\u89c4\u5f8b\u5730\u6bcf 3 \u5e74\u66f4\u65b0\u2f00\u6b21\u3002<\/p>\n\n\n\n<p><br><strong> \u4e00.\u5217\u8868\u521d\u59cb\u5316<\/strong>\uff1aC++11\u4e2d\u7684{} \u2022 C++11\u4ee5\u540e\u60f3\u7edf\u2f00\u521d\u59cb\u5316\u2f45\u5f0f\uff0c\u8bd5\u56fe\u5b9e\u73b0\u2f00\u5207\u5bf9\u8c61\u7686\u53ef\u2f64{}\u521d\u59cb\u5316\uff0c{}\u521d\u59cb\u5316\u4e5f\u53eb\u505a\u5217\u8868\u521d\u59cb\u5316\u3002                                                                                                                                                            \u2022 \u5185\u7f6e\u7c7b\u578b\u2f40\u6301\uff0c\u2f83\u5b9a\u4e49\u7c7b\u578b\u4e5f\u2f40\u6301\uff0c\u2f83\u5b9a\u4e49\u7c7b\u578b\u672c\u8d28\u662f\u7c7b\u578b\u8f6c\u6362\uff0c\u4e2d\u95f4\u4f1a\u4ea7\u2f63\u4e34\u65f6\u5bf9\u8c61\uff0c\u6700\u540e\u4f18\u5316\u4e86\u4ee5\u540e\u53d8\u6210\u76f4\u63a5\u6784\u9020\u3002     \u4e0b\u9762\u4e3e\u4f8b\uff1a<\/p>\n\n\n\n<p> c++\u652f\u6301\u7684\uff1a\n\u5185\u7f6e\u7c7b\u578b\u652f\u6301\nint x1 = { 2 };\n\u81ea\u5b9a\u4e49\u7c7b\u578b\u4e5f\u53ef\u4ee5\u7528\u5217\u8868\u521d\u59cb\u5316\n\u6ca1\u6709\u5b9e\u73b0\u62f7\u8d1d\u6784\u9020\nDate d1 = { 2025,1,1 };\nconst Date&#038; d2 = { 2024,7,25 };\n\u53ef\u4ee5\u7701\u7565=\nDate dd1{ 2025,1,1 };\nconst Date&#038; dd2{ 2024,7,25 };\n\u6784\u9020+\u62f7\u8d1d\u6784\u9020+\u4f18\u5316\nvector<int>vt = { 1,1,1,1 };\nvector<int>vt1{ 1,1,1,1 };\n\u76f4\u63a5\u6784\u9020 initializer_liast\u76f4\u63a5\u6784\u9020\nvector<int>vt2 ({ 1,1,1,1 });\ninitializer_list<int>lli = { 1,1,1,1 };<\/p>\n\n\n\n<p><strong>\u4e8c.\u53f3\u503c\u5f15\u7528\u548c\u79fb\u52a8\u8bed\u4e49<\/strong>\uff1a<\/p>\n\n\n\n<p>\u5de6\u503c\u662f\u8868\u793a\u6570\u636e\u7684\u8868\u8fbe\u5f0f\uff0c\u4e00\u822c\u5177\u6709\u6301\u4e45\u72b6\u6001\uff0c\u53ef\u4ee5\u53d6\u5730\u5740\uff0c\u53ef\u4ee5\u51fa\u73b0\u5728\u8d4b\u503c\u7b26\u53f7\u5de6\u8fb9\u6216\u8005\u53f3\u8fb9                                                                                  \u53f3\u503c\u4e5f\u53ef\u4ee5\u662f\u6570\u636e\u7684\u8868\u8fbe\u5f0f\uff0c\u4e0d\u80fd\u53d6\u5730\u5740\uff0c\u53ef\u4ee5\u51fa\u73b0\u5728\u8d4b\u503c\u7b26\u53f7\u53f3\u8fb9\uff0c\u4f46\u662f\u4e0d\u80fd\u51fa\u73b0\u5728\u53f3\u8fb9\u3002                                  \u5de6\u503c\uff1a\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f,\u53ef\u4ee5\u83b7\u53d6\u5b83\u7684\u5730\u5740(\u6700\u7ec8\u7279\u70b9)<br>\u5e38\u89c1\u7684\u5de6\u503cp,b,c,s,s[0]<br>int* p = new int(0);<br>int b = 1;<br>const int c = b;<br>*p = 10;<br>string s(&#8220;11111&#8221;);<br>s[0] = &#8216;x&#8217;;<br>int*&#038; x = p;\/\/\u5de6\u503c\u5f15\u7528\u7ed9\u5de6\u503c\u8d77\u522b\u540d<br>\u53f3\u503c\uff1a<br>10;<br>x+y<br>fmin(x,y)<br>string(11111)                                                                                                                                                                 <\/p>\n\n\n\n<p>\u5de6\u503c\u5f15\u7528\u548c\u53f3\u503c\u5f15\u7528\uff1a                                                                                                                                                               Type&#038; r1 = x; Type&#038;&#038; rr1 = y;                                                                                                                        \u7b2c\u4e00\u4e2a\u662f\u5de6\u503c\u5f15\u7528\u3002 \u7b2c\u4e8c\u4e2a\u662f\u53f3\u503c\u5f15\u7528\u3002                                                                                                                    \u5de6\u503c\u5f15\u2f64\u4e0d\u80fd\u76f4\u63a5\u5f15\u2f64\u53f3\u503c\uff0c\u4f46\u662fconst\u5de6\u503c\u5f15\u2f64\u53ef\u4ee5\u5f15\u2f64\u53f3\u503c                                                                    \u53f3\u503c\u5f15\u2f64\u4e0d\u80fd\u76f4\u63a5\u5f15\u2f64\u5de6\u503c\uff0c\u4f46\u662f\u53f3\u503c\u5f15\u2f64\u53ef\u4ee5\u5f15\u2f64move(\u5de6\u503c)\u5982\uff1a                                                                       \u5de6\u503c\u5f15\u7528\u4e0d\u80fd\u76f4\u63a5\u5f15\u7528\u53f3\u503c\uff0cconst\u5de6\u503c\u53ef\u4ee5\u5f15\u7528\u53f3\u503c <br> \u4f8b\uff1afunc(const T&#038;x)\u53ef\u4ee5\u4f20\u5de6\u503c\u4e5f\u53ef\u4ee5\u4f20\u53f3\u503c<br>const int&#038; rx1 = 10;<br>const double&#038; rx2 = x + y;<br>const string&#038;rx4=string(&#8220;11111&#8221;);<br>\u53f3\u503c\u5f15\u7528\u4e0d\u80fd\u76f4\u63a5\u5f15\u7528\u5de6\u503c\uff0c\u4f46\u53f3\u503c\u5f15\u7528\u53ef\u4ee5\u4f7f\u7528move(\u5de6\u503c)<br>int&#038;&#038; rrx1 = move(b);<br>cout << rrx1 << endl;<br>move\uff1a\u5e95\u5c42\u672c\u8d28\u5c31\u662f\u5f3a\u8f6c\uff0c\u5c06\u5de6\u503c\u8f6c\u5316\u4e3a\u53f3\u503c<br> \u5de6\u503c\/\u53f3\u503c\u5f15\u7528\u5c5e\u6027\u662f\u5de6\u503c<br>rr1\u5c5e\u6027\u662f\u5de6\u503c\uff0c\u6240\u4ee5\u4e0d\u80fd\u88abmove\u7ed1\u5b9a\uff0c\u9664\u975emove\u4e00\u4e0b<br>\u5de6\u503c\u5f15\u7528\u548c\u53f3\u503c\u5f15\u7528\u7684\u751f\u547d\u5468\u671f<br> \u4f8b\uff1afunc(const T&#038;x)\u53ef\u4ee5\u4f20\u5de6\u503c\u4e5f\u53ef\u4ee5\u4f20\u53f3\u503c                                                                                         const \u7684\u5de6\u503c\u5f15\u2f64\u4e5f\u80fd\u5ef6\u2ed3\u4e34\u65f6\u5bf9\u8c61\u2f63\u5b58\u671f\uff0c\u4f46\u8fd9\u4e9b\u5bf9\u8c61\u4e0d\u80fd\u88ab\u4fee\u6539                                                         <\/p>\n\n\n\n<p>\u4e8c.\u53ef\u53d8\u53c2\u6570\u6a21\u7248<\/p>\n\n\n\n<p>template <class ...Args> void Func(Args&#8230; args) {}                                                                                                 template <class ...Args> void Func(Args&#038;&#8230; args) {}                                                                                      template <class ...Args> void Func(Args&#038;&#038;&#8230; args) {}                                                                                                   \u603b\u7ed3\uff1a\u51fd\u6570\u6a21\u7248\uff0c\u4e00\u4e2a\u51fd\u6570\u6a21\u7248\u5b9e\u4f8b\u5316\u51fa\u6765\u4e0d\u540c\u7c7b\u578b\u53c2\u6570\u7684\u51fd\u6570<br>\u53ef\u53d8\u53c2\u6570\u6a21\u7248\uff0c\u4e00\u4e2a\u53ef\u53d8\u53c2\u6570\u6a21\u7248\u5b9e\u4f8b\u5316\u51fa\u6765\u591a\u4e2a\u4e0d\u540c\u53c2\u6570\u4e2a\u6570\u7684\u6a21\u7248<br>\u5305\u6269\u5c55<\/p>\n\n\n\n<p>\u5305\u7684\u6269\u5c55:                                                                                                                                                        \u8fd9\u91cc\u4ecb\u7ecd\u4e00\u79cd\u65b9\u6cd5\u8fed\u4ee3\u6cd5\uff1a<\/p>\n\n\n\n<p>void ShowList()<br>{<br>\/\/ \u7f16\u8bd1\u5668\u65f6\u9012\u5f52\u7684\u7ec8\u2f4c\u6761\u4ef6\uff0c\u53c2\u6570\u5305\u662f0\u4e2a\u65f6\uff0c\u76f4\u63a5\u5339\u914d\u8fd9\u4e2a\u51fd\u6570<br>cout << endl; } template<br>void ShowList(T x, Args\u2026 args)<br>{<br>cout << x << \" \"; \/\/ args\u662fN\u4e2a\u53c2\u6570\u7684\u53c2\u6570\u5305 \/\/ \u8c03\u2f64ShowList\uff0c\u53c2\u6570\u5305\u7684\u7b2c\u2f00\u4e2a\u4f20\u7ed9x\uff0c\u5269\u4e0bN-1\u4f20\u7ed9\u7b2c\u2f06\u4e2a\u53c2\u6570\u5305 ShowList(args\u2026); } \/\/ \u7f16\u8bd1\u65f6\u9012\u5f52\u63a8\u5bfc\u89e3\u6790\u53c2\u6570 template<br>void Print(Args\u2026 args)<br>{<br>ShowList(args\u2026);<br>}<br>int main()<br>{<br>Print();<br>Print(1);<br>Print(1, string(&#8220;xxxxx&#8221;));<br>Print(1, string(&#8220;xxxxx&#8221;), 2.2);<br>return 0;<br>}<\/p>\n\n\n\n<p>                                                                                                          <\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++11 \u662f C++ \u7684\u7b2c\u2f06\u4e2a\u4e3b\u8981\u7248\u672c\uff0c\u5e76\u4e14\u662f\u4ece C++98 \u8d77\u7684\u6700\u91cd\u8981\u66f4\u65b0\u3002\u5b83\u5f15\u2f0a\u4e86\u2f24\u91cf\u66f4\u6539\uff0c\u6807\u51c6\u5316\u4e86\u65e2\u6709&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[4],"tags":[],"class_list":["post-169","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=169"}],"version-history":[{"count":4,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":873,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions\/873"}],"wp:attachment":[{"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tgwttt.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}