{"id":103,"date":"2021-08-27T01:47:32","date_gmt":"2021-08-26T17:47:32","guid":{"rendered":"http:\/\/139.224.63.49\/?p=103"},"modified":"2021-08-27T02:01:48","modified_gmt":"2021-08-26T18:01:48","slug":"%e9%81%87%e5%88%b0%e7%9a%84%e4%b8%80%e4%b8%aa%e5%85%b3%e4%ba%8e%e6%99%ba%e8%83%bd%e6%8c%87%e9%92%88%e7%9a%84%e9%97%ae%e9%a2%98%e3%80%82%e3%80%82","status":"publish","type":"post","link":"http:\/\/iamnear.top\/?p=103","title":{"rendered":"\u9047\u5230\u7684\u4e00\u4e2a\u5173\u4e8e\u667a\u80fd\u6307\u9488\u7684\u95ee\u9898\u3002\u3002\u5df2\u89e3\u51b3"},"content":{"rendered":"\n<p>\u4e3a\u4ec0\u4e48\u5982\u4e0b\u4ee3\u7801\u53ef\u4ee5\u901a\u8fc7\u7f16\u8bd1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void func(const shared_ptr&lt;const int>&amp; p)\n{\n\n}\nint main()\n{\n    shared_ptr&lt;int> p = make_shared&lt;int>();\n    func(p);\n}<\/code><\/pre>\n\n\n\n<p>\u800c\u53ea\u8981\u53bb\u6389func\u51fd\u6570\u53c2\u6570\u7684const\uff0c\u5982\u4e0b\uff0c\u5c31\u4e0d\u80fd\u901a\u8fc7\u7f16\u8bd1\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void func(shared_ptr&lt;const int>&amp; p)\n{\n\n}\nint main()\n{\n    shared_ptr&lt;int> p = make_shared&lt;int>();\n    func(p);\n}<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u6211\u4e00\u822c\u5199\u51fd\u6570\u4f20\u667a\u80fd\u6307\u9488\u90fd\u662f\u7528\u503c\u4f20\u9012\uff0c\u6240\u4ee5\u4ee5\u524d\u6ca1\u78b0\u5230\u8fd9\u4e9b\u95ee\u9898\u3002\u521a\u521a\u5728\u7528PCL\u5e93\uff0c\u770b\u91cc\u9762\u53c8\u8fd9\u6837\u7684\u5199\u6cd5\u3002\u7ea0\u7ed3\u4e3a\u4ec0\u4e48\u7b2c\u4e00\u79cd\u53ef\u4ee5\u901a\u8fc7\u7f16\u8bd1\uff1f\u5f15\u7528\u4f20\u9012\u4e0d\u4e00\u6837\u7684\u7c7b\u578b\u4e3a\u5565\u53ef\u4ee5\u5462\uff1f\u5982\u679c\u662f\u503c\u4f20\u9012\u7684\u8bdd\uff0c\u90a3\u4e48\u6307\u5411const\u7684\u667a\u80fd\u6307\u9488\u53ef\u4ee5\u901a\u8fc7\u6307\u5411\u975econst\u7684\u6307\u9488\u6765\u6784\u9020\uff0c\u5f88\u597d\u7406\u89e3\u3002\u4f46\u662f\u5982\u679c\u5f15\u7528\u7684\u8bdd\uff0c\u660e\u660e\u7c7b\u578b\u4e0d\u4e00\u6837\u554a\u3002\u3002<\/p>\n\n\n\n<p>\u67e5\u4e86\u4e0b\u8d44\u6599\uff0c\u6709\u70b9\u61c2\u4e86\uff0c\u5982\u4e0b\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class A\n{\npublic:\n    A(int a)\n    {\n\n    }\n};\nvoid func1(const A&amp; a)\n{\n\n}\nvoid func2(A&amp; a)\n{\n\n}\nint main()\n{\n    func1(3);\n    func2(3);\n}<\/code><\/pre>\n\n\n\n<p>func1\u6b63\u5e38\uff0cfunc2\u62a5\u9519\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u5982\u679c\u4f20\u4e00\u4e2a\u5bf9\u8c61\u7684const reference\uff0c\u5982\u679c\u4f60\u7ed9\u7684\u53c2\u6570\u53ef\u4ee5\u8f6c\u5316\u4e3a\u6307\u5b9a\u7684\u7c7b\uff0c\u7f16\u8bd1\u5668\u4f1a\u5e2e\u4f60\u8f6c<\/p>\n\n\n\n<p>\u5982\u679c\u4f20\u7684\u4e00\u4e2a\u5bf9\u8c61\u7684reference\uff0c\u7f16\u8bd1\u5668\u8ba4\u4e3a\u4f60\u53ef\u80fd\u5bf9\u8fd9\u4e2a\u5bf9\u8c61\u505a\u4fee\u6539\uff0c\u6240\u4ee5\u4e0d\u4f1a\u5e2e\u4f60\u81ea\u52a8\u8f6c\u3002\u56e0\u4e3a\u6bd4\u5982\u7f16\u8bd1\u5668\u5982\u679c\u81ea\u52a8\u628aint\u8f6c\u6210A\uff0c\u7136\u540e\u4f60\u7684func2\u5bf9A\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u4f46\u662fmain\u51fd\u6570\u4f5c\u4e3a\u8c03\u7528\u8005\u5bf9\u6b64\u662f\u5b8c\u5168\u4e0d\u77e5\u9053\u7684\uff0c\u8fd9\u5c31\u8fdd\u53cd\u4e86\u975econst\u7684\u672c\u610f\u548c\u8bbe\u8ba1\u76ee\u7684\u3002\u56e0\u6b64\u7f16\u8bd1\u5668\u4f1a\u5728func2\u5904\u62a5\u9519annot bind non-const lvalue reference of type \u2018A&amp;\u2019 to an rvalue of type \u2018A\u2019<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u5982\u4e0b\u4ee3\u7801\u53ef\u4ee5\u901a\u8fc7\u7f16\u8bd1\uff1a \u800c\u53ea\u8981\u53bb\u6389func\u51fd\u6570\u53c2\u6570\u7684const\uff0c\u5982\u4e0b\uff0c\u5c31\u4e0d\u80fd\u901a\u8fc7\u7f16\u8bd1\u4e86 \u56e0\u4e3a\u6211&hellip; <a href=\"http:\/\/iamnear.top\/?p=103\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u9047\u5230\u7684\u4e00\u4e2a\u5173\u4e8e\u667a\u80fd\u6307\u9488\u7684\u95ee\u9898\u3002\u3002\u5df2\u89e3\u51b3<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":{"0":"post-103","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-c_plus_plus","7":"h-entry","9":"h-as-article"},"_links":{"self":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":2,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":106,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions\/106"}],"wp:attachment":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}