{"id":2055,"date":"2023-01-19T16:41:19","date_gmt":"2023-01-19T08:41:19","guid":{"rendered":"https:\/\/courtship.top\/?p=2055"},"modified":"2023-01-19T16:41:19","modified_gmt":"2023-01-19T08:41:19","slug":"%e6%b7%b1%e6%8b%b7%e8%b4%9d%e4%b8%8e%e6%b5%85%e6%8b%b7%e8%b4%9d","status":"publish","type":"post","link":"https:\/\/courtship.top\/index.php\/2023\/01\/19\/%e6%b7%b1%e6%8b%b7%e8%b4%9d%e4%b8%8e%e6%b5%85%e6%8b%b7%e8%b4%9d\/","title":{"rendered":"\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>c\u8bed\u8a00\u4e2d\u6587\u7f51<\/p>\n<cite>http:\/\/m.biancheng.net\/view\/2336.html<\/cite><\/blockquote>\n\n\n\n<p>\u5176\u5b9e\u53d1\u73b0\u8fd9\u4e9b\u57fa\u7840\u9762\u8bd5\u9898\u786e\u5b9e\u5f88\u57fa\u7840 \u4f46\u662f\u4ee5\u524d\u90fd\u6ca1\u6709\u53bb\u6ce8\u610f\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9a\u4e49<\/h2>\n\n\n\n<p>\u5982\u666e\u901a\u7684\u8d4b\u503c\uff0c\u6ca1\u6709\u6307\u9488\u548c\u5185\u5b58\u5206\u914d\u7684\u7c7b\u5bf9\u8c61\u4e92\u76f8\u8d4b\u503c\u662f\u4ee5\u62f7\u8d1d\u7684\u65b9\u5f0f\u521d\u59cb\u5316\u5bf9\u8c61\uff0c\u6309\u7167\u9ed8\u8ba4\u7684\u4e8c\u8fdb\u5236\u4f4d\u65b9\u5f0f\u8fdb\u884c\u62f7\u8d1d\uff0c\u8fd9\u79cd\u9ed8\u8ba4\u7684\u62f7\u8d1d\u65b9\u5f0f\u5c31\u662f<strong>\u6d45\u62f7\u8d1d<\/strong>\uff0c<strong>\u8fd9\u548c\u8c03\u7528 memcpy() \u51fd\u6570\u7684\u6548\u679c\u975e\u5e38\u7c7b\u4f3c\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-pullquote\"><blockquote><p>\u5bf9\u4e8e\u7b80\u5355\u7684\u7c7b\uff0c\u9ed8\u8ba4\u7684\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u4e00\u822c\u5c31\u591f\u7528\u4e86\uff0c\u6211\u4eec\u4e5f\u6ca1\u6709\u5fc5\u8981\u518d\u663e\u5f0f\u5730\u5b9a\u4e49\u4e00\u4e2a\u529f\u80fd\u7c7b\u4f3c\u7684\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u3002<strong>\u4f46\u662f\u5f53\u7c7b\u6301\u6709\u5176\u5b83\u8d44\u6e90\u65f6\uff0c\u4f8b\u5982\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58\u3001\u6307\u5411\u5176\u4ed6\u6570\u636e\u7684\u6307\u9488\u7b49<\/strong>\uff0c\u9ed8\u8ba4\u7684\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u5c31\u4e0d\u80fd\u62f7\u8d1d\u8fd9\u4e9b\u8d44\u6e90\u4e86\uff0c<strong>\u6211\u4eec\u5fc5\u987b\u663e\u5f0f\u5730\u5b9a\u4e49\u62f7\u8d1d\u6784\u9020\u51fd\u6570\uff0c\u4ee5\u5b8c\u6574\u5730\u62f7\u8d1d\u5bf9\u8c61\u7684\u6240\u6709\u6570\u636e\u3002<\/strong><\/p><\/blockquote><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;cstdlib>\nusing namespace std;\n\n\/\/\u53d8\u957f\u6570\u7ec4\u7c7b\nclass Array{\npublic:\n    Array(int len);\n    Array(const Array &amp;arr);  \/\/\u62f7\u8d1d\u6784\u9020\u51fd\u6570\n    ~Array();\npublic:\n    int operator&#91;](int i) const { return m_p&#91;i]; }  \/\/\u83b7\u53d6\u5143\u7d20\uff08\u8bfb\u53d6\uff09\n    int &amp;operator&#91;](int i){ return m_p&#91;i]; }  \/\/\u83b7\u53d6\u5143\u7d20\uff08\u5199\u5165\uff09\n    int length() const { return m_len; }\nprivate:\n    int m_len;\n    int *m_p;\n};\n\nArray::Array(int len): m_len(len){\n    m_p = (int*)calloc( len, sizeof(int) );\n}\n\nArray::Array(const Array &amp;arr){  \/\/\u62f7\u8d1d\u6784\u9020\u51fd\u6570\n    this->m_len = arr.m_len;\n    this->m_p = (int*)calloc( this->m_len, sizeof(int) );\n    memcpy( this->m_p, arr.m_p, m_len * sizeof(int) );\n}\n\nArray::~Array(){ free(m_p); }\n\n\/\/\u6253\u5370\u6570\u7ec4\u5143\u7d20\nvoid printArray(const Array &amp;arr){\n    int len = arr.length();\n    for(int i=0; i&lt;len; i++){\n        if(i == len-1){\n            cout&lt;&lt;arr&#91;i]&lt;&lt;endl;\n        }else{\n            cout&lt;&lt;arr&#91;i]&lt;&lt;\", \";\n        }\n    }\n}\n\nint main(){\n    Array arr1(10);\n    for(int i=0; i&lt;10; i++){\n        arr1&#91;i] = i;\n    }\n\n    Array arr2 = arr1;\n    arr2&#91;5] = 100;\n    arr2&#91;3] = 29;\n\n    printArray(arr1);\n    printArray(arr2);\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u663e\u5f0f\u5730\u5b9a\u4e49\u4e86\u62f7\u8d1d\u6784\u9020\u51fd\u6570\uff0c<strong>\u5b83\u9664\u4e86\u4f1a\u5c06\u539f\u6709\u5bf9\u8c61\u7684\u6240\u6709\u6210\u5458\u53d8\u91cf\u62f7\u8d1d\u7ed9\u65b0\u5bf9\u8c61\uff0c\u8fd8\u4f1a\u4e3a\u65b0\u5bf9\u8c61\u518d\u5206\u914d\u4e00\u5757\u5185\u5b58\uff0c\u5e76\u5c06\u539f\u6709\u5bf9\u8c61\u6240\u6301\u6709\u7684\u5185\u5b58\u4e5f\u62f7\u8d1d\u8fc7\u6765<\/strong>\u3002<strong>\u8fd9\u6837\u505a\u7684\u7ed3\u679c\u662f\uff0c\u539f\u6709\u5bf9\u8c61\u548c\u65b0\u5bf9\u8c61\u6240\u6301\u6709\u7684\u52a8\u6001\u5185\u5b58\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u66f4\u6539\u4e00\u4e2a\u5bf9\u8c61\u7684\u6570\u636e\u4e0d\u4f1a\u5f71\u54cd\u53e6\u5916\u4e00\u4e2a\u5bf9\u8c61<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-pullquote\"><blockquote><p><strong>\u8fd9\u79cd\u5c06\u5bf9\u8c61\u6240\u6301\u6709\u7684\u5176\u5b83\u8d44\u6e90\u4e00\u5e76\u62f7\u8d1d\u7684\u884c\u4e3a\u53eb\u505a\u6df1\u62f7\u8d1d\uff0c\u6211\u4eec\u5fc5\u987b\u663e\u5f0f\u5730\u5b9a\u4e49\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u624d\u80fd\u8fbe\u5230\u6df1\u62f7\u8d1d\u7684\u76ee\u7684\u3002<\/strong><\/p><\/blockquote><\/figure>\n\n\n\n<p>\u6df1\u62f7\u8d1d\u7684\u4f8b\u5b50\u6bd4\u6bd4\u7686\u662f\uff0c\u9664\u4e86\u4e0a\u9762\u7684\u53d8\u957f\u6570\u7ec4\u7c7b\uff0c\u52a8\u6001\u6570\u7ec4\u7c7b\u4e5f\u9700\u8981\u6df1\u62f7\u8d1d\uff1b\u6b64\u5916\uff0c\u6807\u51c6\u6a21\u677f\u5e93\uff08STL\uff09\u4e2d\u7684 string\u3001vector\u3001stack\u3001set\u3001map \u7b49\u4e5f\u90fd\u5fc5\u987b\u4f7f\u7528\u6df1\u62f7\u8d1d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f55\u65f6\u4f7f\u7528\u6df1\u62f7\u8d1d\u6216\u8005\u6d45\u62f7\u8d1d<\/h2>\n\n\n\n<p><strong>\u5982\u679c\u4e00\u4e2a\u7c7b\u62e5\u6709\u6307\u9488\u7c7b\u578b\u7684\u6210\u5458\u53d8\u91cf\uff0c\u90a3\u4e48\u7edd\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u5c31\u9700\u8981\u6df1\u62f7\u8d1d<\/strong>\uff0c\u56e0\u4e3a\u53ea\u6709\u8fd9\u6837\uff0c\u624d\u80fd\u5c06\u6307\u9488\u6307\u5411\u7684\u5185\u5bb9\u518d\u590d\u5236\u51fa\u4e00\u4efd\u6765\uff0c\u8ba9\u539f\u6709\u5bf9\u8c61\u548c\u65b0\u751f\u5bf9\u8c61\u76f8\u4e92\u72ec\u7acb\uff0c\u5f7c\u6b64\u4e4b\u95f4\u4e0d\u53d7\u5f71\u54cd\u3002<\/p>\n\n\n\n<p><strong>\u5982\u679c\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u6ca1\u6709\u6307\u9488<\/strong>\uff0c\u4e00\u822c\u6d45\u62f7\u8d1d\u8db3\u4ee5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>c\u8bed\u8a00\u4e2d\u6587\u7f51 http:\/\/m.biancheng.net\/view\/2336.html \u5176\u5b9e\u53d1\u73b0\u8fd9\u4e9b\u57fa\u7840\u9762\u8bd5\u9898\u786e\u5b9e\u5f88\u57fa\u7840 \u4f46\u662f\u4ee5 &#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-2055","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2055","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=2055"}],"version-history":[{"count":0,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2055\/revisions"}],"wp:attachment":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/media?parent=2055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/categories?post=2055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/tags?post=2055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}