{"id":357,"date":"2024-06-12T13:13:36","date_gmt":"2024-06-12T05:13:36","guid":{"rendered":"http:\/\/www.cmd137blog.top\/?p=357"},"modified":"2024-06-12T13:13:38","modified_gmt":"2024-06-12T05:13:38","slug":"c%e8%bf%90%e7%ae%97%e7%ac%a6%e9%87%8d%e8%bd%bd%ef%bc%9a%e4%b8%8d%e5%90%8c%e9%87%8d%e8%bd%bd%e6%96%b9%e5%bc%8f%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.cmd137blog.top\/?p=357","title":{"rendered":"C++\u8fd0\u7b97\u7b26\u91cd\u8f7d\uff1a\u4e0d\u540c\u91cd\u8f7d\u65b9\u5f0f\u7684\u95ee\u9898"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u539f\u9898\uff1a<\/h1>\n\n\n\n<p>\u72d0\u72f8\u7cbe<\/p>\n\n\n\n<p>\u63cf\u8ff0<\/p>\n\n\n\n<p>\u53cd\u6d3e\u662f\u4e09\u53ea\u6210\u7cbe\u7684\u72d0\u72f8\uff1a\u72d0\u6bcd\uff0c\u72d0\u5973\u548c\u72d0\u5b50\u963f\u62d0\u3002<br>\u72d0\u72f8\u6210\u7cbe\u540e\uff0c\u5f00\u59cb\u4f5c\u6076\u591a\u7aef\u3002\u5047\u8bbe\u6709<code>Fox<\/code>\u7c7b\uff0c\u6709\u81ea\u5df1\u7684\u5927\u5c0f<code>int size<\/code>\u548c\u6cd5\u529b<code>int power<\/code>\u3002<br>\u72d0\u72f8\u7cbe\u7532\u5982\u679c\u548c\u72d0\u72f8\u7cbe\u4e59\u5408\u4f53(&amp;&amp;)\uff0c\u4f1a\u53d8\u6210\u4e00\u53ea\u66f4\u5927\u7684\u72d0\u72f8\u4e19\uff0c<code>size<\/code>\u53d8\u6210\u539f\u6765\u7532\u548c\u4e59\u7684<code>size<\/code>\u4e4b\u548c\uff0c<code>power<\/code>\u4f1a\u53d8\u6210\u539f\u6765\u7532\u548c\u4e59\u7684<code>power<\/code>\u5e73\u5747\u503c\u3002<br>\u72d0\u72f8\u8fd8\u4f1a\u98d8(~)\uff0c\u98d8\u7684\u65f6\u5019\uff0csize\u4f1a\u81ea\u52a8\u53d8\u6210\u539f\u6765\u7684\u4e09\u5206\u4e4b\u4e00\u3002<\/p>\n\n\n\n<p>\u8bf7\u53c2\u8003\u4e0b\u9762\u7684<code>main<\/code>\u7528\u4e00\u4e2a<code>Fox<\/code>\u7c7b\u6765\u5b9e\u73b0\u8fd9\u4e9b\u6cd5\u529b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    int s1, p1, s2, p2;\n    cin &gt;&gt; s1 &gt;&gt; p1 &gt;&gt; s2 &gt;&gt; p2;\n\n    Fox C1(s1, p1);\n    Fox C2(s2, p2);\n\n    C1.show();    \/\/ \u73b0\u8eab\n\n    ~(~C1);        \/\/ \u98d82\u6b21\n    C1.show();    \/\/ \u518d\u73b0\u8eab\n\n    Fox C3 = C1 &amp;&amp; C2;    \/\/ \u5408\u4f53\n    C3.show();    \/\/ \u73b0\u8eab\n\n    return 0;\n}\n\n<\/code><\/pre>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>\u4e24\u53ea\u72d0\u72f8\u7684\u4fe1\u606f<code>size power<\/code><\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>\u89c1<code>main<\/code>\u51fd\u6570\u8f93\u51fa\u53ca\u8f93\u51fa\u6837\u4f8b\u3002\u5176\u4e2d\uff0cshow\u51fd\u6570\u4f9d\u6b21\u8f93\u51fa<code>size power<\/code>\uff0c\u4e2d\u95f4\u4ee5\u7a7a\u683c\u5206\u9694\uff0c\u6700\u540e\u6362\u884c\u3002<\/p>\n\n\n\n<p>\u8f93\u5165\u6837\u4f8b 1&nbsp;<a><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">100 50 120 80<\/pre>\n\n\n\n<p>\u8f93\u51fa\u6837\u4f8b 1<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">100 50\n11 50\n131 65<\/pre>\n\n\n\n<p>\u63d0\u793a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4ec5\u9700\u63d0\u4ea4Fox\u7c7b\u4ee3\u7801\u548c\u76f8\u5173\u51fd\u6570\u4ee3\u7801\u3002<\/li>\n\n\n\n<li>\u5b9e\u73b0\u76f8\u5173\u8fd0\u7b97\u7b26\u91cd\u8f7d\u3002\u98d82\u6b21\u7684\u5730\u65b9\u6ce8\u610f\u51fd\u6570\u8fd4\u56de\u503c\u5199\u6cd5\u3002<\/li>\n\n\n\n<li>\u6574\u6570\u8ba1\u7b97\u8fc7\u7a0b\u4e0d\u8003\u8651\u5c0f\u6570\u90e8\u5206\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u6765\u6e90 hlu<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u95ee\u9898\uff1a<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>Fox&amp; operator~()\n\t{\n\t\tsize\/=3;\n\t\treturn *this;\n\t}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Fox operator~()\n\t{\n\t\treturn Fox(size\/3, power);\n\t}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Fox&amp; operator~()\n\t{\n\t\treturn Fox(size \/ 3, power);\n\t}<\/code><\/pre>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u8fd9\u4e09\u79cd\u5199\u6cd5\u770b\u8d77\u6765\u4e00\u6837\u5374\u53c8\u4e0d\u540c\u7ed3\u679c\uff1f\u5728\u8fd9\u9053\u9898\u4e2d\uff0c\u53ea\u6709\u7b2c\u4e00\u79cd\u6b63\u786e\uff0c\u7b2c\u4e09\u4e2d\u751a\u81f3\u4e0d\u80fd\u6b63\u786e\u7f16\u8bd1<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u89e3\u51b3\uff1a<\/h1>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u95ee\u9898\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u8003\u8651C++\u8fd0\u7b97\u7b26\u91cd\u8f7d\u7684\u8bed\u4e49\u548c\u8fd4\u56de\u7c7b\u578b\u3002\u5bf9\u4e8e\u5355\u76ee\u8fd0\u7b97\u7b26<code>~<\/code>\uff0c\u5982\u679c\u6211\u4eec\u8981\u5b9e\u73b0\u4e00\u4e2a\u201c\u98d8\u201d\u7684\u529f\u80fd\uff0c\u901a\u5e38\u6211\u4eec\u4f1a\u5e0c\u671b\u8fd9\u4e2a\u64cd\u4f5c\u80fd\u591f\u6539\u53d8\u5f53\u524d\u5bf9\u8c61\u7684\u72b6\u6001\uff0c\u5e76\u4e14\u80fd\u591f\u94fe\u5f0f\u8c03\u7528\uff08\u5373\u8fde\u7eed\u98d8\u591a\u6b21\uff09\u3002\u8fd9\u5c31\u8981\u6c42\u6211\u4eec\u7684\u91cd\u8f7d\u8fd0\u7b97\u7b26\u80fd\u591f\u8fd4\u56de\u4e00\u4e2a\u5f15\u7528\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u8fde\u7eed\u8c03\u7528\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u79cd\u5199\u6cd5<\/strong>\uff1a<code>Fox&amp; operator~() { size \/= 3; return *this; }<\/code>\u8fd9\u79cd\u5199\u6cd5\u662f\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u5b83\u8fd4\u56de\u4e86\u5f53\u524d\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u5141\u8bb8\u94fe\u5f0f\u8c03\u7528\u3002\u4f8b\u5982\uff0c<code>~(~C1)<\/code>\u9996\u5148\u5bf9<code>C1<\/code>\u8c03\u7528\u4e00\u6b21<code>~<\/code>\uff0c\u7136\u540e\u4f7f\u7528\u7ed3\u679c\u518d\u6b21\u8c03\u7528<code>~<\/code>\uff0c\u56e0\u4e3a\u6bcf\u6b21\u8c03\u7528\u90fd\u8fd4\u56de\u4e86\u5bf9\u8c61\u7684\u5f15\u7528\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u79cd\u5199\u6cd5<\/strong>\uff1a<code>Fox operator~() { return Fox(size \/ 3, power); }<\/code>\u8fd9\u79cd\u5199\u6cd5\u8fd4\u56de\u4e86\u4e00\u4e2a\u65b0\u7684<code>Fox<\/code>\u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5f15\u7528\u3002\u8fd9\u5728\u903b\u8f91\u4e0a\u662f\u6709\u95ee\u9898\u7684\uff0c\u56e0\u4e3a\u5982\u679c\u6309\u7167\u8fd9\u79cd\u5199\u6cd5\uff0c<code>~(~C1)<\/code>\u5c06\u4e0d\u4f1a\u5de5\u4f5c\uff0c\u56e0\u4e3a\u7b2c\u4e00\u4e2a<code>~<\/code>\u4f1a\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684<code>Fox<\/code>\u5bf9\u8c61\uff0c\u800c\u7b2c\u4e8c\u4e2a<code>~<\/code>\u65e0\u6cd5\u5728\u8fd9\u4e2a\u65b0\u5bf9\u8c61\u4e0a\u8c03\u7528\u6765\u5b9e\u73b0\u94fe\u5f0f\u98d8\u7684\u6548\u679c\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e09\u79cd\u5199\u6cd5<\/strong>\uff1a<code>Fox&amp; operator~() { return Fox(size \/ 3, power); }<\/code>\u8fd9\u79cd\u5199\u6cd5\u8bd5\u56fe\u8fd4\u56de\u5f53\u524d\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4f46\u5b9e\u9645\u4e0a\u8fd4\u56de\u7684\u662f\u65b0\u521b\u5efa\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u8fd9\u662f\u6709\u95ee\u9898\u7684\uff0c\u56e0\u4e3a\u8fd4\u56de\u7684\u5f15\u7528\u6307\u5411\u7684\u662f\u4e00\u4e2a\u5c40\u90e8\u7684\u4e34\u65f6\u5bf9\u8c61\uff0c\u4e00\u65e6\u51fd\u6570\u8fd4\u56de\uff0c\u8fd9\u4e2a\u5c40\u90e8\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u5c31\u7ed3\u675f\u4e86\uff0c\u5bfc\u81f4\u8fd4\u56de\u7684\u5f15\u7528\u60ac\u7a7a\uff08dangling reference\uff09\u3002\u8fd9\u5c06\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u7f16\u8bd1\u5668\u901a\u5e38\u4e5f\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u5b83\u8fdd\u53cd\u4e86C++\u7684\u89c4\u5219\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3\u4e00\u4e0b\uff1a<\/h3>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u8fd9\u4e9b\u5199\u6cd5\u4e0d\u540c\uff1f<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u8bed\u4e49\u5dee\u5f02<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c\u4e00\u79cd\u5199\u6cd5\u4fee\u6539\u5f53\u524d\u5bf9\u8c61\uff0c\u9002\u7528\u4e8e\u9700\u8981\u6539\u53d8\u5bf9\u8c61\u72b6\u6001\u7684\u573a\u666f\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e8c\u79cd\u5199\u6cd5\u521b\u5efa\u65b0\u5bf9\u8c61\uff0c\u9002\u7528\u4e8e\u9700\u8981\u4fdd\u7559\u539f\u59cb\u5bf9\u8c61\u7684\u573a\u666f\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e09\u79cd\u5199\u6cd5\u5728\u8bed\u4e49\u4e0a\u662f\u6df7\u4e71\u7684\uff0c\u56e0\u4e3a\u5b83\u8bd5\u56fe\u8fd4\u56de\u4e00\u4e2a\u5f15\u7528\uff0c\u4f46\u5b9e\u9645\u4e0a\u8fd4\u56de\u7684\u662f\u5c40\u90e8\u5bf9\u8c61\u7684\u5f15\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u7f16\u8bd1\u95ee\u9898<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c\u4e00\u79cd\u5199\u6cd5\u662f\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u5b83\u9075\u5faa\u4e86C++\u7684\u89c4\u5219\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e8c\u79cd\u5199\u6cd5\u867d\u7136\u903b\u8f91\u4e0a\u6709\u95ee\u9898\uff0c\u4f46\u81f3\u5c11\u53ef\u4ee5\u7f16\u8bd1\u901a\u8fc7\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e09\u79cd\u5199\u6cd5\u8fdd\u53cd\u4e86C++\u7684\u89c4\u5219\uff0c\u56e0\u4e3a\u5b83\u8bd5\u56fe\u8fd4\u56de\u5c40\u90e8\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u9519\u8bef\u3002<\/li>\n<\/ul>\n\n\n\n<p>AC\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n\nusing namespace std;\n\nclass Fox\n{\nprivate:\n\tint size;\n\tint power;\npublic:\n\tFox(int s,int p):size(s),power(p)\n\t{\n\t}\n\tvoid show()\n\t{\n\t\tcout&lt;&lt;size&lt;&lt;\" \"&lt;&lt;power&lt;&lt;endl;\n\t}\n\t\n\tFox&amp; operator~()\n\t{\n\t\tsize\/=3;\n\t\treturn *this;\n\t}\n\t\n\t\n\tfriend Fox operator&amp;&amp;(Fox &amp; c1,Fox &amp; c2);\n};\n\nFox operator&amp;&amp;(Fox &amp; c1,Fox &amp; c2)\n\t{\n\t\treturn Fox(c1.size+c2.size,(c1.power+c2.power)\/2);\n\t}\n\nint main()\n{\n    int s1, p1, s2, p2;\n    cin >> s1 >> p1 >> s2 >> p2;\n\n    Fox C1(s1, p1);\n    Fox C2(s2, p2);\n\n    C1.show();    \/\/ \u73b0\u8eab\n\n    ~(~C1);        \/\/ \u98d82\u6b21\n    C1.show();    \/\/ \u518d\u73b0\u8eab\n\n    Fox C3 = C1 &amp;&amp; C2;    \/\/ \u5408\u4f53\n    C3.show();    \/\/ \u73b0\u8eab\n\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u9898\uff1a \u72d0\u72f8\u7cbe \u63cf\u8ff0 \u53cd\u6d3e\u662f\u4e09\u53ea\u6210\u7cbe\u7684\u72d0\u72f8\uff1a\u72d0\u6bcd\uff0c\u72d0\u5973\u548c\u72d0\u5b50\u963f\u62d0\u3002\u72d0\u72f8\u6210\u7cbe\u540e\uff0c\u5f00\u59cb\u4f5c\u6076\u591a\u7aef\u3002\u5047\u8bbe\u6709Fox\u7c7b\uff0c\u6709 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[23,35],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-35"],"_links":{"self":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":2,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":359,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions\/359"}],"wp:attachment":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}