{"id":2053,"date":"2023-01-19T15:14:54","date_gmt":"2023-01-19T07:14:54","guid":{"rendered":"https:\/\/courtship.top\/?p=2053"},"modified":"2024-06-07T14:38:57","modified_gmt":"2024-06-07T06:38:57","slug":"%e7%a7%bb%e5%8a%a8%e6%9e%84%e9%80%a0","status":"publish","type":"post","link":"https:\/\/courtship.top\/index.php\/2023\/01\/19\/%e7%a7%bb%e5%8a%a8%e6%9e%84%e9%80%a0\/","title":{"rendered":"\u79fb\u52a8\u6784\u9020"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>CSDN\uff1aa\u53ea\u5982\u521d\u89c1 \/ c\u8bed\u8a00\u4e2d\u6587\u7f51<\/p>\n<cite>http:\/\/t.csdn.cn\/oSedW \/ http:\/\/m.biancheng.net\/view\/7847.html<\/cite><\/blockquote>\n\n\n\n<p><strong>\u79fb\u52a8\u6784\u9020\u662fC++11\u6807\u51c6\u4e2d\u63d0\u4f9b\u7684\u4e00\u79cd\u65b0\u7684\u6784\u9020\u65b9\u6cd5\u3002<\/strong><\/p>\n\n\n\n<p>\u5148\u4e3e\u4e2a\u751f\u6d3b\u4f8b\u5b50\uff0c\u4f60\u6709\u4e00\u672c\u4e66\uff0c\u4f60\u4e0d\u60f3\u770b\uff0c\u4f46\u6211\u5f88\u60f3\u770b\uff0c\u90a3\u4e48\u6211\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u6211\u80fd\u770b\u8fd9\u672c\u4e66\uff1f\u6709\u4e24\u79cd\u505a\u6cd5\uff0c\u4e00\u79cd\u662f\u4f60\u76f4\u63a5\u628a\u4e66\u4ea4\u7ed9\u6211\uff0c\u53e6\u4e00\u79cd\u662f\u6211\u53bb\u4e70\u4e00\u4e9b\u7a3f\u7eb8\u6765\uff0c\u7136\u540e\u7167\u7740\u4f60\u8fd9\u672c\u4e66\u4e00\u5b57\u4e00\u53e5\u6284\u5230\u7a3f\u7eb8\u4e0a\u3002<\/p>\n\n\n\n<p>\u663e\u7136\uff0c\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u5f88\u6d6a\u8d39\u65f6\u95f4\uff0c\u4f46\u8fd9\u6b63\u662f\u6709\u4e9b\u6df1\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u7684\u505a\u6cd5\uff0c\u800c\u79fb\u52a8\u6784\u9020\u51fd\u6570\u4fbf\u80fd\u50cf\u7b2c\u4e00\u79cd\u505a\u6cd5\u4e00\u6837\u7701\u65f6\uff0c\u7b2c\u4e00\u79cd\u505a\u6cd5\u5728 C++ \u4e2d\u53eb\u505a<strong>\u5b8c\u7f8e\u8f6c\u53d1<\/strong>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728C++11\u4e4b\u524d\uff0c\u5982\u679c\u8981\u5c06\u6e90\u5bf9\u8c61\u7684\u72b6\u6001\u8f6c\u79fb\u5230\u76ee\u6807\u5bf9\u8c61\u53ea\u80fd\u901a\u8fc7\u590d\u5236\u3002<br>\u800c\u73b0\u5728\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u6ca1\u6709\u5fc5\u8981\u590d\u5236\u5bf9\u8c61\uff0c\u53ea\u9700\u8981\u79fb\u52a8\u5b83\u4eec\u3002<\/li>\n\n\n\n<li>C++11\u5f15\u5165\u79fb\u52a8\u8bed\u4e49\uff1a\u6e90\u5bf9\u8c61\u8d44\u6e90\u7684\u63a7\u5236\u6743\u5168\u90e8\u4ea4\u7ed9\u76ee\u6807\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u6240\u8c13\u79fb\u52a8\u8bed\u4e49\uff0c\u6307\u7684\u5c31\u662f\u4ee5\u79fb\u52a8\u800c\u975e\u6df1\u62f7\u8d1d\u7684\u65b9\u5f0f\u521d\u59cb\u5316\u542b\u6709\u6307\u9488\u6210\u5458\u7684\u7c7b\u5bf9\u8c61\u3002\u7b80\u5355\u7684\u7406\u89e3\uff0c\u79fb\u52a8\u8bed\u4e49\u6307\u7684\u5c31\u662f\u5c06\u5176\u4ed6\u5bf9\u8c61\uff08\u901a\u5e38\u662f\u4e34\u65f6\u5bf9\u8c61\uff09\u62e5\u6709\u7684\u5185\u5b58\u8d44\u6e90\u201c\u79fb\u4e3a\u5df2\u7528\u201d\u3002<\/p>\n\n\n\n<p>\u79fb\u52a8\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u548c\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u4e0d\u540c\uff0c\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u662f\u4e00\u4e2a\u5de6\u503c\u5f15\u7528\uff0c\u4f46\u662f\u79fb\u52a8\u6784\u9020\u51fd\u6570\u7684\u521d\u503c\u662f\u4e00\u4e2a\u53f3\u503c\u5f15\u7528\u3002\u8fd9\u610f\u5473\u7740\uff0c\u79fb\u52a8\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570<strong>\u662f\u4e00\u4e2a\u53f3\u503c\u6216\u8005\u5c06\u4ea1\u503c\u7684\u5f15\u7528<\/strong>\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u53ea\u6709\u5f53\u7528\u4e00\u4e2a\u53f3\u503c\uff0c\u6216\u8005\u5c06\u4ea1\u503c\u521d\u59cb\u5316\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u624d\u4f1a\u8c03\u7528\u79fb\u52a8\u6784\u9020\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Str\n{\npublic:\n    char *str;\n    Str(char value&#91;])\n    {\n        cout &lt;&lt; \"\u666e\u901a\u6784\u9020\u51fd\u6570...\" &lt;&lt; endl;\n        str = NULL;\n        int len = strlen(value);\n        str = (char *)malloc(len + 1);\n        memset(str, 0, len + 1);\n        strcpy(str, value);\n    }\n    Str(const Str &amp;s)\n    {\n        cout &lt;&lt; \"\u62f7\u8d1d\u6784\u9020\u51fd\u6570...\" &lt;&lt; endl;\n        str = NULL;\n        int len = strlen(s.str);\n        str = (char *)malloc(len + 1);\n        memset(str, 0, len + 1);\n        strcpy(str, s.str);\n    }\n    Str(Str &amp;&amp;s)\n    {\n        cout &lt;&lt; \"\u79fb\u52a8\u6784\u9020\u51fd\u6570...\" &lt;&lt; endl;\n        str = NULL;\n        str = s.str;\n        s.str = NULL;\n    }\n    ~Str()\n    {\n        cout &lt;&lt; \"\u6790\u6784\u51fd\u6570\" &lt;&lt; endl;\n        if (str != NULL)\n        {\n            free(str);\n            str = NULL;\n        }\n    }\n};\nint main()\n{\n    char value&#91;] = \"I love zx\";\n    Str x(\"hhh\");\n    Str s(value);\n    vector&lt;Str&gt; vs;\n    vs.push_back(move(s));\n    \/\/ vs.push_back(s);\n    cout &lt;&lt; vs&#91;0].str &lt;&lt; endl;\n    if (s.str != NULL)\n        cout &lt;&lt; s.str &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u901a\u5e38\u5728\u7c7b\u4e2d\u81ea\u5b9a\u4e49\u79fb\u52a8\u6784\u9020\u51fd\u6570\u7684\u540c\u65f6\uff0c\u4f1a\u518d\u4e3a\u5176\u81ea\u5b9a\u4e49\u4e00\u4e2a\u9002\u5f53\u7684\u62f7\u8d1d\u6784\u9020\u51fd\u6570\uff0c\u7531\u6b64\u5f53\u7528\u6237\u5229\u7528\u53f3\u503c\u521d\u59cb\u5316\u7c7b\u5bf9\u8c61\u65f6\uff0c\u4f1a\u8c03\u7528\u79fb\u52a8\u6784\u9020\u51fd\u6570\uff1b\u4f7f\u7528\u5de6\u503c\uff08\u975e\u53f3\u503c\uff09\u521d\u59cb\u5316\u7c7b\u5bf9\u8c61\u65f6\uff0c\u4f1a\u8c03\u7528\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u79fb\u52a8\u6784\u9020\u5e38\u89c1\u4e8eSTL<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>    _CONSTEXPR20 void push_back(const _Ty&amp; _Val) { \/\/ insert element at end, provide strong guarantee\n        emplace_back(_Val);\n    }\n\n    _CONSTEXPR20 void push_back(_Ty&amp;&amp; _Val) {\n        \/\/ insert by moving into element at end, provide strong guarantee\n        emplace_back(_STD move(_Val));\n    }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">std::move()\u4f5c\u7528<\/h3>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5de6\u503c\u521d\u59cb\u5316\u540c\u7c7b\u5bf9\u8c61\u53ea\u80fd\u901a\u8fc7\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u5b8c\u6210\uff0c\u5982\u679c\u60f3\u8c03\u7528\u79fb\u52a8\u6784\u9020\u51fd\u6570\uff0c\u5219\u5fc5\u987b\u4f7f\u7528\u53f3\u503c\u8fdb\u884c\u521d\u59cb\u5316\u3002<strong>C++11 \u6807\u51c6\u4e2d\u4e3a\u4e86\u6ee1\u8db3\u7528\u6237\u4f7f\u7528\u5de6\u503c\u521d\u59cb\u5316\u540c\u7c7b\u5bf9\u8c61\u65f6\u4e5f\u901a\u8fc7\u79fb\u52a8\u6784\u9020\u51fd\u6570\u5b8c\u6210\u7684\u9700\u6c42\uff0c\u65b0\u5f15\u5165\u4e86 std::move() \u51fd\u6570<\/strong>\uff0c\u5b83\u53ef\u4ee5<strong>\u5c06\u5de6\u503c\u5f3a\u5236\u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u53f3\u503c<\/strong>\uff0c\u7531\u6b64\u4fbf\u53ef\u4ee5\u4f7f\u7528\u79fb\u52a8\u6784\u9020\u51fd\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f18\u70b9<\/h2>\n\n\n\n<p>\u79fb\u52a8\u6784\u9020\u51fd\u6570\u662fc++11\u7684\u65b0\u7279\u6027\uff0c\u79fb\u52a8\u6784\u9020\u51fd\u6570\u4f20\u5165\u7684\u53c2\u6570\u662f\u4e00\u4e2a\u53f3\u503c \u7528&amp;&amp;\u6807\u51fa\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u8bb2\u8bb2\u62f7\u8d1d\u6784\u9020\u51fd\u6570\uff1a\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u662f\u5148\u5c06\u4f20\u5165\u7684\u53c2\u6570\u5bf9\u8c61\u8fdb\u884c\u4e00\u6b21\u6df1\u62f7\u8d1d\uff0c\u518d\u4f20\u7ed9\u65b0\u5bf9\u8c61\u3002\u8fd9\u5c31\u4f1a\u6709\u4e00\u6b21\u62f7\u8d1d\u5bf9\u8c61\u7684\u5f00\u9500\uff0c\u62f7\u8d1d\u7684\u5185\u5b58\u8d8a\u5927\u8d8a\u8017\u8d39\u65f6\u95f4\uff0c\u5e76\u4e14\u8fdb\u884c\u4e86\u6df1\u62f7\u8d1d\uff0c\u5c31\u9700\u8981\u7ed9\u5bf9\u8c61\u5206\u914d\u5730\u5740\u7a7a\u95f4\u3002\u800c\u79fb\u52a8\u6784\u9020\u51fd\u6570\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u62f7\u8d1d\u5f00\u9500\u800c\u4ea7\u751f\u7684\u3002<\/p>\n\n\n\n<p><strong>\u79fb\u52a8\u6784\u9020\u51fd\u6570\u9996\u5148\u5c06\u4f20\u9012\u53c2\u6570\u7684\u5185\u5b58\u5730\u5740\u7a7a\u95f4\u63a5\u7ba1\uff0c\u7136\u540e\u5c06\u5185\u90e8\u6240\u6709\u6307\u9488\u8bbe\u7f6e\u4e3anullptr\uff0c\u5e76\u4e14\u5728\u539f\u5730\u5740\u4e0a\u8fdb\u884c\u65b0\u5bf9\u8c61\u7684\u6784\u9020\uff0c\u6700\u540e\u8c03\u7528\u539f\u5bf9\u8c61\u7684\u7684\u6790\u6784\u51fd\u6570\uff0c\u8fd9\u6837\u505a\u65e2\u4e0d\u4f1a\u4ea7\u751f\u989d\u5916\u7684\u62f7\u8d1d\u5f00\u9500\uff0c\u4e5f\u4e0d\u4f1a\u7ed9\u65b0\u5bf9\u8c61\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u3002\u5373\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\uff0c\u8282\u7701\u5185\u5b58\u6d88\u8017\u3002<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u79fb\u52a8\u6784\u9020\u662fC++11\u6807\u51c6\u4e2d\u63d0\u4f9b\u7684\u4e00\u79cd\u65b0\u7684\u6784\u9020\u65b9\u6cd5<\/strong><\/li>\n\n\n\n<li><strong>\u79fb\u52a8\u6784\u9020\u63a5\u7ba1\u6e90\u5bf9\u8c61\uff0c\u65e2\u4e0d\u4f1a\u4ea7\u751f\u989d\u5916\u7684\u62f7\u8d1d\u5f00\u9500\uff0c\u4e5f\u4e0d\u4f1a\u7ed9\u65b0\u5bf9\u8c61\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u3002\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\uff0c\u8282\u7701\u5185\u5b58\u6d88\u8017\u3002<\/strong><\/li>\n\n\n\n<li><strong>\u79fb\u52a8\u6784\u9020\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u662f\u81ea\u8eab\u7c7b\u578b\u7684\u53f3\u503c\u5f15\u7528<\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>CSDN\uff1aa\u53ea\u5982\u521d\u89c1 \/ c\u8bed\u8a00\u4e2d\u6587\u7f51 http:\/\/t.csdn.cn\/oSedW \/ http:\/\/m.biancheng.n &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[22],"tags":[],"class_list":["post-2053","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/comments?post=2053"}],"version-history":[{"count":1,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2053\/revisions"}],"predecessor-version":[{"id":2387,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2053\/revisions\/2387"}],"wp:attachment":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/media?parent=2053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/categories?post=2053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/tags?post=2053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}