{"id":46837,"date":"2025-07-30T04:18:11","date_gmt":"2025-07-29T20:18:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46837.html"},"modified":"2025-07-30T04:18:11","modified_gmt":"2025-07-29T20:18:11","slug":"%e3%80%90c%e3%80%91%e7%ac%ac%e5%8d%81%e4%ba%94%e8%8a%82-%e4%b8%80%e6%96%87%e8%af%a6%e8%a7%a3-%e7%bb%a7%e6%89%bf","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46837.html","title":{"rendered":"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f"},"content":{"rendered":"<p>hello&#xff0c;\u6211\u662f\u4e91\u8fb9\u6709\u4e2a\u7a3b\u8349\u4eba&#xff0c;C&#043;&#043;\u9886\u57df\u4e07\u7c89\u535a\u4e3b&#xff0c;\u4e0e\u4f60\u5206\u4eab\u4e13\u4e1a\u77e5\u8bc6^(*&#xffe3;(oo)&#xffe3;)^&#xff01;<\/p>\n<p>\u300aC&#043;&#043;\u300b\u672c\u7bc7\u6587\u7ae0\u6240\u5c5e\u4e13\u680f\u2014\u6301\u7eed\u66f4\u65b0\u4e2d\u2014\u6b22\u8fce\u8ba2\u9605&#xff01;<\/p>\n<p style=\"text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" class=\"right\" height=\"163\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201750-68892c6ece72c.jpg\" width=\"250\" \/><\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E7%BB%A7%E6%89%BF%E7%9A%84%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%AE%9A%E4%B9%89-toc\" style=\"margin-left:80px\">\u4e00\u3001\u7ee7\u627f\u7684\u6982\u5ff5\u4e0e\u5b9a\u4e49<\/p>\n<p id=\"1.2%20%E7%BB%A7%E6%89%BF%E5%AE%9A%E4%B9%89-toc\" style=\"margin-left:120px\">1.2 \u7ee7\u627f\u5b9a\u4e49<\/p>\n<p id=\"%E3%80%90%E5%AE%9A%E4%B9%89%E6%A0%BC%E5%BC%8F%E3%80%91-toc\" style=\"margin-left:160px\">\u3010\u5b9a\u4e49\u683c\u5f0f\u3011<\/p>\n<p id=\"%E3%80%90%E7%BB%A7%E6%89%BF%E5%9F%BA%E7%B1%BB%E6%88%90%E5%91%98%E8%AE%BF%E9%97%AE%E6%96%B9%E5%BC%8F%E7%9A%84%E5%8F%98%E5%8C%96%E3%80%91-toc\" style=\"margin-left:160px\">\u3010\u7ee7\u627f\u57fa\u7c7b\u6210\u5458\u8bbf\u95ee\u65b9\u5f0f\u7684\u53d8\u5316\u3011<\/p>\n<p id=\"1.3%20%E7%BB%A7%E6%89%BF%E7%B1%BB%E6%A8%A1%E7%89%88-toc\" style=\"margin-left:120px\">1.3 \u7ee7\u627f\u7c7b\u6a21\u7248<\/p>\n<p id=\"%E3%80%90%E6%B3%A8%E6%84%8F%E5%9C%BA%E6%99%AF%E3%80%91-toc\" style=\"margin-left:160px\">\u3010\u6ce8\u610f\u573a\u666f\u3011<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E5%9F%BA%E7%B1%BB%E5%92%8C%E6%B4%BE%E2%BD%A3%E7%B1%BB%E9%97%B4%E7%9A%84%E8%BD%AC%E6%8D%A2-toc\" style=\"margin-left:80px\">\u4e8c\u3001\u57fa\u7c7b\u548c\u6d3e\u2f63\u7c7b\u95f4\u7684\u8f6c\u6362<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%AD%E7%9A%84%E4%BD%9C%E7%94%A8%E5%9F%9F-toc\" style=\"margin-left:80px\">\u4e09\u3001\u7ee7\u627f\u4e2d\u7684\u4f5c\u7528\u57df<\/p>\n<p id=\"3.1%20%E9%9A%90%E8%97%8F%E8%A7%84%E5%88%99-toc\" style=\"margin-left:120px\">3.1 \u9690\u85cf\u89c4\u5219<\/p>\n<p id=\"3.2%20%E8%80%83%E5%AF%9F%E7%BB%A7%E6%89%BF%E4%BD%9C%E7%94%A8%E5%9F%9F%E7%9B%B8%E5%85%B3%E9%80%89%E6%8B%A9%E9%A2%98-toc\" style=\"margin-left:120px\">3.2 \u8003\u5bdf\u7ee7\u627f\u4f5c\u7528\u57df\u76f8\u5173\u9009\u62e9\u9898<\/p>\n<p id=\"%E3%80%90A%E5%92%8CB%E7%B1%BB%E4%B8%AD%E7%9A%84%E4%B8%A4%E4%B8%AAfun%E6%9E%84%E6%88%90%E4%BB%80%E4%B9%88%E5%85%B3%E7%B3%BB%EF%BC%88%EF%BC%89%E3%80%91-toc\" style=\"margin-left:160px\">\u3010A\u548cB\u7c7b\u4e2d\u7684\u4e24\u4e2afun\u6784\u6210\u4ec0\u4e48\u5173\u7cfb&#xff08;&#xff09;\u3011<\/p>\n<p id=\"%E3%80%90%E4%B8%8B%E2%BE%AF%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%BC%96%E8%AF%91%E8%BF%90%E2%BE%8F%E7%BB%93%E6%9E%9C%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%88%EF%BC%89%E3%80%91-toc\" style=\"margin-left:160px\">\u3010\u4e0b\u2faf\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fd0\u2f8f\u7ed3\u679c\u662f\u4ec0\u4e48&#xff08;&#xff09;\u3011<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E6%B4%BE%E2%BD%A3%E7%B1%BB%E7%9A%84%E9%BB%98%E8%AE%A4%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:80px\">\u56db\u3001\u6d3e\u2f63\u7c7b\u7684\u9ed8\u8ba4\u6210\u5458\u51fd\u6570<\/p>\n<p id=\"4.1%C2%A04%E4%B8%AA%E5%B8%B8%E2%BB%85%E9%BB%98%E8%AE%A4%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:120px\">4.1\u00a04\u4e2a\u5e38\u2ec5\u9ed8\u8ba4\u6210\u5458\u51fd\u6570<\/p>\n<p id=\"%E3%80%90%E6%9C%89%E5%85%B3%E4%B8%8A%E9%9D%A2%E7%AC%AC%E5%9B%9B%E7%82%B9%E3%80%91%C2%A0-toc\" style=\"margin-left:160px\">\u3010\u6709\u5173\u4e0a\u9762\u7b2c\u56db\u70b9\u3011\u00a0<\/p>\n<p id=\"4.2%C2%A0%E5%AE%9E%E7%8E%B0%E2%BC%80%E4%B8%AA%E4%B8%8D%E8%83%BD%E8%A2%AB%E7%BB%A7%E6%89%BF%E7%9A%84%E7%B1%BB-toc\" style=\"margin-left:120px\">4.2\u00a0\u5b9e\u73b0\u2f00\u4e2a\u4e0d\u80fd\u88ab\u7ee7\u627f\u7684\u7c7b<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%8E%E5%8F%8B%E5%85%83-toc\" style=\"margin-left:80px\">\u4e94\u3001\u7ee7\u627f\u4e0e\u53cb\u5143<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%8E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98-toc\" style=\"margin-left:80px\">\u516d\u3001\u7ee7\u627f\u4e0e\u9759\u6001\u6210\u5458<\/p>\n<p id=\"%C2%A0%E4%B8%83%E3%80%81%E5%A4%9A%E7%BB%A7%E6%89%BF%E5%8F%8A%E5%85%B6%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:80px\">\u4e03\u3001\u591a\u7ee7\u627f\u53ca\u5176\u83f1\u5f62\u7ee7\u627f\u95ee\u9898<\/p>\n<p id=\"7.1%C2%A0%E7%BB%A7%E6%89%BF%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:120px\">7.1\u00a0\u7ee7\u627f\u6a21\u578b<\/p>\n<p id=\"7.2%20%E8%99%9A%E7%BB%A7%E6%89%BF-toc\" style=\"margin-left:120px\">7.2 \u865a\u7ee7\u627f<\/p>\n<p id=\"%C2%A0%E3%80%90%E5%B0%8F%E9%A2%98%E7%9B%AE%E3%80%91-toc\" style=\"margin-left:160px\">\u00a0\u3010\u5c0f\u9898\u76ee\u3011<\/p>\n<p id=\"7.3%C2%A0%E5%A4%9A%E7%BB%A7%E6%89%BF%E4%B8%AD%E6%8C%87%E9%92%88%E5%81%8F%E7%A7%BB%E9%97%AE%E9%A2%98%EF%BC%9F-toc\" style=\"margin-left:120px\">7.3\u00a0\u591a\u7ee7\u627f\u4e2d\u6307\u9488\u504f\u79fb\u95ee\u9898&#xff1f;<\/p>\n<p id=\"7.4%C2%A0IO%E5%BA%93%E4%B8%AD%E7%9A%84%E8%8F%B1%E5%BD%A2%E8%99%9A%E6%8B%9F%E7%BB%A7%E6%89%BF-toc\" style=\"margin-left:120px\">7.4\u00a0IO\u5e93\u4e2d\u7684\u83f1\u5f62\u865a\u62df\u7ee7\u627f<\/p>\n<p id=\"%E5%85%AB%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%8E%E7%BB%84%E5%90%88-toc\" style=\"margin-left:80px\">\u516b\u3001\u7ee7\u627f\u4e0e\u7ec4\u5408<\/p>\n<p id=\"%E5%9C%BA%E6%99%AF1%EF%BC%9A%E7%BB%A7%E6%89%BF%E7%A4%BA%E4%BE%8B%EF%BC%88is-a%E5%85%B3%E7%B3%BB%EF%BC%89-toc\" style=\"margin-left:120px\">\u573a\u666f1&#xff1a;\u7ee7\u627f\u793a\u4f8b&#xff08;is-a\u5173\u7cfb&#xff09;<\/p>\n<p id=\"%E5%9C%BA%E6%99%AF2%EF%BC%9A%E7%BB%84%E5%90%88%E7%A4%BA%E4%BE%8B%EF%BC%88has-a%E5%85%B3%E7%B3%BB%EF%BC%89-toc\" style=\"margin-left:120px\">\u573a\u666f2&#xff1a;\u7ec4\u5408\u793a\u4f8b&#xff08;has-a\u5173\u7cfb&#xff09;<\/p>\n<p id=\"%E5%9C%BA%E6%99%AF3%EF%BC%9A%E7%BB%A7%E6%89%BF%2B%E7%BB%84%E5%90%88%E6%B7%B7%E5%90%88%E4%BD%BF%E7%94%A8-toc\" style=\"margin-left:120px\">\u573a\u666f3&#xff1a;\u7ee7\u627f&#043;\u7ec4\u5408\u6df7\u5408\u4f7f\u7528<\/p>\n<p id=\"%E7%BB%A7%E6%89%BF%20vs%20%E7%BB%84%E5%90%88%E7%9A%84%E9%80%89%E6%8B%A9%E5%8E%9F%E5%88%99-toc\" style=\"margin-left:120px\">\u7ee7\u627f vs \u7ec4\u5408\u7684\u9009\u62e9\u539f\u5219<\/p>\n<p id=\"%E5%86%8D%E4%B8%BE%E4%B8%80%E4%BE%8B-toc\" style=\"margin-left:120px\">\u518d\u4e3e\u4e00\u4f8b<\/p>\n<hr id=\"hr-toc\" \/>\n<p>\u6b63\u6587\u5f00\u59cb\u2014\u2014<\/p>\n<\/p>\n<h4 id=\"%E4%B8%80%E3%80%81%E7%BB%A7%E6%89%BF%E7%9A%84%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%AE%9A%E4%B9%89\">\u4e00\u3001\u7ee7\u627f\u7684\u6982\u5ff5\u4e0e\u5b9a\u4e49<\/h4>\n<p>1.1 \u7ee7\u627f\u7684\u6982\u5ff5<\/p>\n<p><span style=\"color:#4da8ee\"><span style=\"background-color:null\">\u7ee7\u627f(inheritance)\u673a\u5236<\/span><\/span><span style=\"color:#0d0016\">\u662f\u2faf\u5411\u5bf9\u8c61\u7a0b\u5e8f\u8bbe\u8ba1<\/span><span style=\"color:#4da8ee\">\u4f7f\u4ee3\u7801\u53ef\u4ee5\u590d\u2f64<\/span><span style=\"color:#0d0016\">\u7684\u6700\u91cd\u8981\u7684\u2f3f\u6bb5&#xff0c;\u5b83\u5141\u8bb8\u6211\u4eec\u5728\u4fdd\u6301\u539f\u6709\u7c7b\u7279\u6027\u7684\u57fa\u7840\u4e0a\u8fdb\u2f8f\u6269\u5c55&#xff0c;\u589e\u52a0\u2f45\u6cd5(\u6210\u5458\u51fd\u6570)\u548c\u5c5e\u6027(\u6210\u5458\u53d8\u91cf)&#xff0c;\u8fd9\u6837\u4ea7\u2f63\u65b0\u7684\u7c7b&#xff0c;\u79f0<\/span><span style=\"color:#4da8ee\"><span style=\"background-color:null\">\u6d3e\u2f63\u7c7b<\/span><\/span><span style=\"color:#0d0016\">\u3002\u7ee7\u627f\u5448\u73b0\u4e86\u2faf\u5411\u5bf9\u8c61\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u5c42\u6b21\u7ed3\u6784&#xff0c;\u4f53\u73b0\u4e86\u7531\u7b80\u5355\u5230\u590d\u6742\u7684\u8ba4\u77e5\u8fc7\u7a0b\u3002\u4ee5\u524d\u6211\u4eec\u63a5\u89e6\u7684\u51fd\u6570\u5c42\u6b21\u7684\u590d\u2f64&#xff0c;\u7ee7\u627f\u662f\u7c7b\u8bbe\u8ba1\u5c42\u6b21\u7684<\/span><span style=\"color:#4da8ee\">\u590d\u7528<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<p>\u4e0b\u2faf\u6211\u4eec\u770b\u5230\u6ca1\u6709\u7ee7\u627f\u4e4b\u524d\u6211\u4eec\u8bbe\u8ba1\u4e86\u4e24\u4e2a\u7c7bStudent\u548cTeacher&#xff0c;Student\u548cTeacher\u90fd\u6709\u59d3\u540d\/\u5730\u5740\/ \u7535\u8bdd\/\u5e74\u9f84\u7b49\u6210\u5458\u53d8\u91cf&#xff0c;\u90fd\u6709identity\u2f9d\u4efd\u8ba4\u8bc1\u7684\u6210\u5458\u51fd\u6570&#xff0c;\u8bbe\u8ba1\u5230\u4e24\u4e2a\u7c7b\u2fa5\u2faf\u5c31\u662f<span style=\"color:#4da8ee\"><span style=\"background-color:null\">\u5197\u4f59<\/span><\/span>\u7684\u3002\u5f53\u7136\u4ed6\u4eec\u4e5f\u6709\u2f00\u4e9b\u4e0d\u540c\u7684\u6210\u5458\u53d8\u91cf\u548c\u51fd\u6570&#xff0c;\u2f50\u5982\u2f7c\u5e08\u72ec\u6709\u6210\u5458\u53d8\u91cf\u662f\u804c\u79f0&#xff0c;\u5b66\u2f63\u7684\u72ec\u6709\u6210\u5458\u53d8\u91cf\u662f\u5b66\u53f7&#xff1b;\u5b66\u2f63\u7684\u72ec\u6709\u6210\u5458\u51fd\u6570\u662f\u5b66\u4e60&#xff0c;\u2f7c\u5e08\u7684\u72ec\u6709\u6210\u5458\u51fd\u6570\u662f\u6388\u8bfe\u3002<\/p>\n<p>class Student<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u8fdb\u2f0a\u6821\u56ed\/\u56fe\u4e66\u9986\/\u5b9e\u9a8c\u5ba4\u5237\u2f06\u7ef4\u7801\u7b49\u2f9d\u4efd\u8ba4\u8bc1<br \/>\nvoid identity()<br \/>\n{<br \/>\n\/\/ &#8230;<br \/>\n}<br \/>\n\/\/ \u5b66\u4e60<br \/>\nvoid study()<br \/>\n{<br \/>\n\/\/ &#8230;<br \/>\n}<br \/>\nprotected:<br \/>\nstring _name &#061; &#034;peter&#034;; \/\/ \u59d3\u540d<br \/>\nstring _address; \/\/ \u5730\u5740<br \/>\nstring _tel; \/\/ \u7535\u8bdd<br \/>\nint _age &#061; 18; \/\/ \u5e74\u9f84<br \/>\nint _stuid;<br \/>\n};<\/p>\n<p>class Teacher<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u8fdb\u2f0a\u6821\u56ed\/\u56fe\u4e66\u9986\/\u5b9e\u9a8c\u5ba4\u5237\u2f06\u7ef4\u7801\u7b49\u2f9d\u4efd\u8ba4\u8bc1<br \/>\nvoid identity()<br \/>\n{<br \/>\n\/\/ &#8230;<br \/>\n}<br \/>\n\/\/ \u6388\u8bfe<br \/>\nvoid teaching()<br \/>\n{<br \/>\n\/\/&#8230;<br \/>\n}<\/p>\n<p>protected:<br \/>\nstring _name &#061; &#034;\u5f20\u4e09&#034;; \/\/ \u59d3\u540d<br \/>\nint _age &#061; 18; \/\/ \u5e74\u9f84<br \/>\nstring _address; \/\/ \u5730\u5740<br \/>\nstring _tel; \/\/ \u7535\u8bdd<br \/>\nstring _title; \/\/ \u804c\u79f0<br \/>\n};<\/p>\n<p>\u00a0\u4e0b\u9762\u6211\u4eec<span style=\"color:#4da8ee\">\u516c\u5171\u7684\u6210\u5458<\/span>\u90fd\u653e\u5230Person\u7c7b\u4e2d&#xff0c;Student\u548cTeacher\u90fd\u7ee7\u627fPerson&#xff0c;\u5c31\u53ef\u4ee5\u590d\u7528\u8fd9\u4e9b\u6210\u5458&#xff0c;\u5c31\u4e0d\u9700\u8981\u91cd\u590d\u5b9a\u4e49\u4e86&#xff0c;\u7701\u53bb\u4e86\u5f88\u591a\u9ebb\u70e6\u3002<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u8fdb\u2f0a\u6821\u56ed\/\u56fe\u4e66\u9986\/\u5b9e\u9a8c\u5ba4\u5237\u2f06\u7ef4\u7801\u7b49\u2f9d\u4efd\u8ba4\u8bc1<br \/>\nvoid identity()<br \/>\n{<br \/>\ncout &lt;&lt; &#034;void identity()&#034; &lt;&lt; _name &lt;&lt; endl;<br \/>\n}<br \/>\nprotected:<br \/>\nstring _name &#061; &#034;\u5f20\u4e09&#034;;  \/\/\u59d3\u540d<br \/>\nstring _address;\/\/\u5730\u5740<br \/>\nstring _tel;\/\/\u7535\u8bdd<br \/>\nint _age &#061; 18;\/\/\u5e74\u9f84<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u5b66\u4e60<br \/>\nvoid study()<br \/>\n{<br \/>\n\/\/ &#8230;<br \/>\n}<br \/>\nprotected:<br \/>\nint _stuid; \/\/ \u5b66\u53f7<br \/>\n};<\/p>\n<p>class Teacher : public Person<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u6388\u8bfe<br \/>\nvoid teaching()<br \/>\n{<br \/>\n\/\/&#8230;<br \/>\n}<br \/>\nprotected:<br \/>\nstring title; \/\/ \u804c\u79f0<br \/>\n}; <\/p>\n<h5 id=\"1.2%20%E7%BB%A7%E6%89%BF%E5%AE%9A%E4%B9%89\">1.2 \u7ee7\u627f\u5b9a\u4e49<\/h5>\n<h6 id=\"%E3%80%90%E5%AE%9A%E4%B9%89%E6%A0%BC%E5%BC%8F%E3%80%91\">\u3010\u5b9a\u4e49\u683c\u5f0f\u3011<\/h6>\n<p>\u4e0b\u2faf\u6211\u4eec\u770b\u5230Person\u662f<span style=\"color:#4da8ee\">\u57fa\u7c7b<\/span>&#xff0c;\u4e5f\u79f0\u4f5c\u2f57\u7c7b\u3002Student\u662f<span style=\"color:#4da8ee\">\u6d3e\u2f63\u7c7b<\/span>&#xff0c;\u4e5f\u79f0\u4f5c\u2f26\u7c7b\u3002(\u56e0\u4e3a\u7ffb\u8bd1\u7684\u539f\u56e0&#xff0c;\u6240\u4ee5\u65e2\u53eb\u57fa\u7c7b\/\u6d3e\u2f63\u7c7b&#xff0c;\u4e5f\u53eb\u2f57\u7c7b\/\u2f26\u7c7b)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1164\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201751-68892c6f27314.png\" width=\"1992\" \/><\/p>\n<h6 id=\"%E3%80%90%E7%BB%A7%E6%89%BF%E5%9F%BA%E7%B1%BB%E6%88%90%E5%91%98%E8%AE%BF%E9%97%AE%E6%96%B9%E5%BC%8F%E7%9A%84%E5%8F%98%E5%8C%96%E3%80%91\">\u3010\u7ee7\u627f\u57fa\u7c7b\u6210\u5458\u8bbf\u95ee\u65b9\u5f0f\u7684\u53d8\u5316\u3011<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"604\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201752-68892c70378dc.png\" width=\"2268\" \/><\/p>\n<\/p>\n<li>\u57fa\u7c7bprivate\u6210\u5458\u5728\u6d3e\u2f63\u7c7b\u4e2d\u2f46\u8bba\u4ee5\u4ec0\u4e48\u2f45\u5f0f\u7ee7\u627f\u90fd\u662f<span style=\"color:#4da8ee\">\u4e0d\u53ef\u89c1<\/span>\u7684\u3002\u8fd9\u2fa5\u7684\u4e0d\u53ef\u2ec5\u662f\u6307\u57fa\u7c7b\u7684\u79c1\u6709\u6210\u5458\u8fd8\u662f\u88ab\u7ee7\u627f\u5230\u4e86\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u4e2d&#xff0c;\u4f46\u662f\u8bed\u6cd5\u4e0a\u9650\u5236\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u4e0d\u7ba1\u5728\u7c7b\u2fa5\u2faf\u8fd8\u662f\u7c7b\u5916\u9762\u90fd\u4e0d\u80fd\u53bb\u8bbf\u95ee\u5b83\u3002<\/li>\n<li>\u57fa\u7c7bprivate\u6210\u5458\u5728\u6d3e\u2f63\u7c7b\u4e2d\u662f\u4e0d\u80fd\u88ab\u8bbf\u95ee&#xff0c;\u5982\u679c\u57fa\u7c7b\u6210\u5458\u4e0d\u60f3\u5728\u7c7b\u5916\u76f4\u63a5\u88ab\u8bbf\u95ee&#xff0c;\u4f46\u9700\u8981\u5728\u6d3e\u2f63\u7c7b \u4e2d\u80fd\u8bbf\u95ee&#xff0c;\u5c31\u5b9a\u4e49\u4e3aprotected\u3002\u53ef\u4ee5\u770b\u51fa\u4fdd\u62a4\u6210\u5458\u9650\u5b9a\u7b26\u662f\u56e0\u7ee7\u627f\u624d\u51fa\u73b0\u7684\u3002<\/li>\n<li>\u5b9e\u9645\u4e0a\u2faf\u7684\u8868\u683c\u6211\u4eec\u8fdb\u2f8f\u2f00\u4e0b\u603b\u7ed3\u4f1a\u53d1\u73b0&#xff0c;\u57fa\u7c7b\u7684\u79c1\u6709\u6210\u5458\u5728\u6d3e\u2f63\u7c7b\u90fd\u662f\u4e0d\u53ef\u2ec5\u3002\u57fa\u7c7b\u7684\u5176\u4ed6\u6210\u5458 \u5728\u6d3e\u2f63\u7c7b\u7684\u8bbf\u95ee\u2f45\u5f0f &#061;&#061; Min(\u6210\u5458\u5728\u57fa\u7c7b\u7684\u8bbf\u95ee\u9650\u5b9a\u7b26&#xff0c;\u7ee7\u627f\u2f45\u5f0f)&#xff0c;public &gt; protected &gt; private\u3002<\/li>\n<li>\u4f7f\u2f64\u5173\u952e\u5b57class\u65f6\u9ed8\u8ba4\u7684\u7ee7\u627f\u2f45\u5f0f\u662fprivate&#xff0c;\u4f7f\u2f64struct\u65f6\u9ed8\u8ba4\u7684\u7ee7\u627f\u2f45\u5f0f\u662fpublic&#xff0c;\u4e0d\u8fc7\u6700\u597d\u663e\u793a\u7684\u5199\u51fa\u7ee7\u627f\u2f45\u5f0f\u3002<\/li>\n<li>\u5728\u5b9e\u9645\u8fd0\u2f64\u4e2d\u2f00\u822c\u4f7f\u2f64\u90fd\u662fpublic\u7ee7\u627f&#xff0c;\u2f0f\u4e4e\u5f88\u5c11\u4f7f\u2f64protetced\/private\u7ee7\u627f&#xff0c;\u4e5f\u4e0d\u63d0\u5021\u4f7f\u7528protetced\/private\u7ee7\u627f&#xff0c;\u56e0\u4e3aprotetced\/private\u7ee7\u627f\u4e0b\u6765\u7684\u6210\u5458\u90fd\u53ea\u80fd\u5728\u6d3e\u2f63\u7c7b\u7684\u7c7b\u2fa5\u2faf\u4f7f\u7528&#xff0c;\u5b9e \u9645\u4e2d\u6269\u5c55\u7ef4\u62a4\u6027\u4e0d\u5f3a\u3002<\/li>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u8fdb\u2f0a\u6821\u56ed\/\u56fe\u4e66\u9986\/\u5b9e\u9a8c\u5ba4\u5237\u2f06\u7ef4\u7801\u7b49\u2f9d\u4efd\u8ba4\u8bc1<br \/>\nvoid identity()<br \/>\n{<br \/>\ncout &lt;&lt; &#034;void identity()&#034; &lt;&lt; _name &lt;&lt; endl;<\/p>\n<p>\/\/\u5982\u679c_age\u5728\u57fa\u7c7b\u4e2d\u662fprivate\u6210\u5458&#xff0c;\u53ef\u4ee5\u5728\u57fa\u7c7b\u6210\u5458\u51fd\u6570\u4e2d\u8bbf\u95ee\u8be5\u6210\u5458\u53d8\u91cf&#xff0c;\u6d3e\u751f\u7c7b\u7531\u4e8e\u7ee7\u627f\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u8be5public\u51fd\u6570&#xff0c;\u5b9e\u73b0\u4e86\u95f4\u63a5\u8bbf\u95eeprivate\u6210\u5458\u53d8\u91cf<br \/>\ncout &lt;&lt; _age &lt;&lt; endl;<br \/>\n}<br \/>\nprotected:<br \/>\nstring _name &#061; &#034;\u5f20\u4e09&#034;;  \/\/\u59d3\u540d<br \/>\nstring _address;\/\/\u5730\u5740<br \/>\nstring _tel;\/\/\u7535\u8bdd<br \/>\nint _age &#061; 18;\/\/\u5e74\u9f84<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u5b66\u4e60<br \/>\nvoid study()<br \/>\n{<br \/>\n\/\/ &#8230;<br \/>\n}<br \/>\n\/\/protected\u53ef\u4ee5\u8bbf\u95ee<br \/>\n\/\/void func()<br \/>\n\/\/{<br \/>\n\/\/_age&#043;&#043;;<br \/>\n\/\/}<br \/>\nprotected:<br \/>\nint _stuid; \/\/ \u5b66\u53f7<br \/>\n};<\/p>\n<p>class Teacher : public Person<br \/>\n{<br \/>\npublic:<br \/>\n\/\/ \u6388\u8bfe<br \/>\nvoid teaching()<br \/>\n{<br \/>\n\/\/&#8230;<br \/>\n}<br \/>\nprotected:<br \/>\nstring title; \/\/ \u804c\u79f0<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\nStudent s;<br \/>\ns.identity();<\/p>\n<p>return 0;<br \/>\n} <\/p>\n<h5 id=\"1.3%20%E7%BB%A7%E6%89%BF%E7%B1%BB%E6%A8%A1%E7%89%88\">1.3 \u7ee7\u627f\u7c7b\u6a21\u7248<\/h5>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f&#xff0c;\u7ee7\u627f\u7c7b\u6a21\u7248&#xff0c;\u5728\u6d3e\u751f\u7c7b\u4e2d\u60f3\u8981\u4f7f\u7528\u57fa\u7c7b\u7684\u6210\u5458\u51fd\u6570\u9700\u8981\u6307\u5b9a\u7c7b\u57df&#xff0c;\u5426\u5219\u5c31\u4f1a\u62a5\u9519&#xff0c;\u663e\u793a\u627e\u4e0d\u5230\u6807\u8bc6\u7b26\u3002stack&lt;int&gt;\u5b9e\u4f8b\u5316\u65f6\u867d\u7136\u4e5f\u5b9e\u4f8b\u5316\u4e86vector&lt;int&gt;&#xff0c;\u4f46\u662f\u6a21\u7248\u662f<span style=\"color:#4da8ee\">\u6309\u9700\u5b9e\u4f8b\u5316<\/span>&#xff08;\u7531\u7c7b\u6a21\u7248\u5b9e\u4f8b\u5316\u4e00\u4e2a\u7c7b\u65f6\u5e76\u4e0d\u4f1a\u5c06\u7c7b\u4e2d\u6240\u6709\u7684\u6210\u5458\u51fd\u6570\u90fd\u8fdb\u884c\u5b9e\u4f8b\u5316&#xff0c;\u800c\u662f\u7528\u54ea\u4e00\u4e2a\u6210\u5458\u51fd\u6570\u624d\u4f1a\u5b9e\u4f8b\u5316\u54ea\u4e2a\u6210\u5458\u51fd\u6570&#xff09;&#xff0c;\u4e5f\u5c31\u662fvector&lt;int&gt;\u867d\u7136\u5b9e\u4f8b\u5316\u4e86&#xff0c;\u4f46\u662fvector&lt;int&gt;\u91cc\u9762\u7684push_back\u5e76\u672a\u8fdb\u884c\u5b9e\u4f8b\u5316&#xff1b;\u6b64\u65f6\u8c03\u7528stack&lt;int&gt;\u91cc\u9762push&#xff0c;push\u91cc\u9762\u53c8\u8c03\u7528\u4e86push_back&#xff0c;\u4f46\u662fpush_back\u8fd8\u6ca1\u6709\u8fdb\u884c\u5b9e\u4f8b\u5316\u5c31\u8c03\u7528\u4e0d\u5230&#xff0c;\u6240\u4ee5\u8981\u6307\u5b9a\u7c7b\u57dfvector&lt;int&gt;\u53bb\u5b9e\u4f8b\u5316\u8be5\u51fd\u6570\u3002<\/p>\n<p>namespace lrq<br \/>\n{<br \/>\ntemplate&lt;class T&gt;<br \/>\nclass stack :public vector&lt;T&gt;<br \/>\n{<br \/>\npublic:<br \/>\nvoid push(const T&amp; x)<br \/>\n{<br \/>\n\/\/\u8fd9\u91cc\u8981\u6307\u5b9a\u7c7b\u57df<br \/>\n\/\/\u57fa\u7c7b\u662f\u7c7b\u6a21\u7248\u65f6&#xff0c;\u9700\u8981\u6307\u5b9a\u4e00\u4e0b\u7c7b\u57df<br \/>\n\/\/\u5426\u5219\u7f16\u8bd1\u62a5\u9519:error C3861: \u201cpush_back\u201d: \u627e\u4e0d\u5230\u6807\u8bc6\u7b26<br \/>\n\/\/\u56e0\u4e3astack&lt;int&gt;\u5b9e\u4f8b\u5316\u65f6&#xff0c;\u4e5f\u5b9e\u4f8b\u5316\u4e86vector&lt;int&gt;<br \/>\n\/\/\u4f46\u662f\u6a21\u7248\u662f\u6309\u9700\u5b9e\u4f8b\u5316&#xff0c;push_back\u7b49\u6210\u5458\u51fd\u6570\u672a\u5b9e\u4f8b\u5316<br \/>\nvector&lt;T&gt;::push_back(x);<br \/>\n\/\/push_back(x);<br \/>\n}<br \/>\nvoid pop()<br \/>\n{<br \/>\nvector&lt;int&gt;::pop_back();<br \/>\n}<br \/>\nconst T&amp; top()<br \/>\n{<br \/>\nreturn vector&lt;int&gt;::back();<br \/>\n}<br \/>\nbool empty()<br \/>\n{<br \/>\nreturn vector&lt;int&gt;::empty();<br \/>\n}<br \/>\n};<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\nlrq::stack&lt;int&gt; st;<br \/>\nst.push(1);<br \/>\nst.push(2);<br \/>\nst.push(3);<br \/>\nst.push(4);<\/p>\n<p>while (!st.empty())<br \/>\n{<br \/>\ncout &lt;&lt; st.top() &lt;&lt; &#034; &#034;;<br \/>\nst.pop();<br \/>\n}<\/p>\n<p>cout &lt;&lt; endl;<\/p>\n<p>return 0;<br \/>\n}<\/p>\n<h6 id=\"%E3%80%90%E6%B3%A8%E6%84%8F%E5%9C%BA%E6%99%AF%E3%80%91\">\u3010\u6ce8\u610f\u573a\u666f\u3011<\/h6>\n<p>template&lt;class Continer&gt;<br \/>\nvoid Print(const Continer&amp; c)<br \/>\n{<br \/>\n\/\/const_iterator\u53ef\u80fd\u662f\u9759\u6001\u6210\u5458\u53d8\u91cf&#xff0c;\u4e5f\u53ef\u80fd\u662f\u5185\u5d4c\u7c7b\u578b&#xff08;\u5185\u90e8\u7c7b&#xff0c;typedef&#xff09;<br \/>\n\/\/\u867d\u7136\u6307\u5b9a\u4e86\u7c7b\u57dfContiner&#xff0c;\u4f46\u662fContiner\u53ea\u662f\u4e2a\u6a21\u7248&#xff0c;\u5e76\u6ca1\u6709\u8fdb\u884c\u5b9e\u4f8b\u5316&#xff0c;\u6a21\u7248\u5185\u90e8\u4e5f\u662f\u65e0\u6cd5\u786e\u5b9a\u7684&#xff0c;\u662f\u4e0d\u80fd\u53bb\u90a3\u91cc\u627e\u4e1c\u897f\u7684&#xff08;\u53ea\u6709\u5b9e\u4f8b\u5316\u624d\u53ef\u4ee5&#xff09;<br \/>\n\/\/\u6dfb\u52a0typename\/class\u610f\u5728\u544a\u8bc9\u7f16\u8bd1\u5668Continer::const_iterator\u662f\u4e00\u4e2a\u7c7b\u578b<br \/>\ntypename Continer::const_iterator it &#061; c.begin();<\/p>\n<p>\/\/\u6216\u8005\u76f4\u63a5\u7528auto<br \/>\n\/\/auto const_iterator it &#061; c.begin();<\/p>\n<p>while (it !&#061; c.end())<br \/>\n{<br \/>\ncout &lt;&lt; *it &lt;&lt; &#034; &#034;;<br \/>\n}<br \/>\ncout &lt;&lt; endl;<br \/>\n} <\/p>\n<hr \/>\n<h4 id=\"%E4%BA%8C%E3%80%81%E5%9F%BA%E7%B1%BB%E5%92%8C%E6%B4%BE%E2%BD%A3%E7%B1%BB%E9%97%B4%E7%9A%84%E8%BD%AC%E6%8D%A2\">\u4e8c\u3001\u57fa\u7c7b\u548c\u6d3e\u2f63\u7c7b\u95f4\u7684\u8f6c\u6362<\/h4>\n<ul>\n<li>public\u7ee7\u627f\u7684\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u53ef\u4ee5\u8d4b\u503c\u7ed9 \u57fa\u7c7b\u7684\u6307\u9488 \/ \u57fa\u7c7b\u7684\u5f15\u2f64\u3002\u8fd9\u2fa5\u6709\u4e2a\u5f62\u8c61\u7684\u8bf4\u6cd5\u53eb<span style=\"color:#4da8ee\">\u5207\u2f5a<\/span>\u6216\u8005\u5207\u5272\u6216\u8005<span style=\"color:#4da8ee\">\u8d4b\u503c\u517c\u5bb9\u8f6c\u6362<\/span>\u3002\u5bd3\u610f\u628a\u6d3e\u2f63\u7c7b\u4e2d\u57fa\u7c7b\u90a3\u90e8\u5206\u5207\u51fa\u6765&#xff0c;\u57fa\u7c7b\u6307\u9488\u6216\u5f15\u2f64\u6307\u5411\u7684\u662f\u6d3e\u2f63\u7c7b\u4e2d\u5207\u51fa\u6765\u7684\u57fa\u7c7b\u90a3\u90e8\u5206\u3002<\/li>\n<li>\u57fa\u7c7b\u5bf9\u8c61\u4e0d\u80fd\u8d4b\u503c\u7ed9\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u3002&#xff08;\u5b50\u7c7b\u7684\u6307\u9488\u6307\u5411\u7236\u7c7b\u7684\u5bf9\u8c61&#xff0c;\u5b50\u7c7b\u7684\u6307\u9488\u76f8\u6bd4\u4e8e\u7236\u7c7b\u7684\u6307\u9488\u591a\u6307\u4e00\u90e8\u5206&#xff0c;\u4f46\u662f\u7236\u7c7b\u6ca1\u6709\u90a3\u4e00\u90e8\u5206&#xff0c;\u8fd9\u5c31\u53ef\u80fd\u9020\u6210\u8d8a\u754c\u7684\u95ee\u9898&#xff09;<\/li>\n<li>\u57fa\u7c7b\u7684\u6307\u9488\u6216\u8005\u5f15\u2f64\u53ef\u4ee5\u901a\u8fc7\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u8d4b\u503c\u7ed9\u6d3e\u2f63\u7c7b\u7684\u6307\u9488\u6216\u8005\u5f15\u2f64\u3002\u4f46\u662f\u5fc5\u987b\u662f\u57fa\u7c7b\u7684\u6307\u9488 \u662f\u6307\u5411\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u65f6\u624d\u662f\u5b89\u5168\u7684\u3002\u8fd9\u2fa5\u57fa\u7c7b\u5982\u679c\u662f\u591a\u6001\u7c7b\u578b&#xff0c;\u53ef\u4ee5\u4f7f\u2f64RTTI(Run-Time Type Information)\u7684dynamic_cast \u6765\u8fdb\u2f8f\u8bc6\u522b\u540e\u8fdb\u2f8f\u5b89\u5168\u8f6c\u6362\u3002&#xff08;ps&#xff1a;\u8fd9\u4e2a\u6211\u4eec\u540e\u2faf\u7c7b\u578b\u8f6c\u6362\u7ae0\u8282\u518d \u5355\u72ec\u4e13\u2ed4\u8bb2\u89e3&#xff0c;\u8fd9\u2fa5\u5148\u63d0\u2f00\u4e0b&#xff09;<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1518\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201753-68892c71c025c.png\" width=\"2065\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1272\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201758-68892c76505eb.png\" width=\"2612\" \/><\/p>\n<p>class Person<br \/>\n{<br \/>\nprotected:<br \/>\nstring _name;<br \/>\nstring _sex;<br \/>\npublic:<br \/>\nint _age &#061; 18;<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\nint _No;<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\nStudent sobj;<br \/>\n\/\/\u8d4b\u503c\u517c\u5bb9\u8f6c\u6362<br \/>\n\/\/1.\u6d3e\u751f\u7c7b\u5bf9\u8c61\u53ef\u4ee5\u8d4b\u503c\u7ed9\u57fa\u7c7b\u7684\u6307\u9488\u6216\u5f15\u7528<br \/>\nPerson* pp &#061; &amp;sobj;<br \/>\nPerson&amp; rp &#061; sobj;<br \/>\nrp._age&#043;&#043;;<\/p>\n<p>double d &#061; 1.1;<br \/>\nconst int&amp; i &#061; d;<\/p>\n<p>string s1 &#061; &#034;123456&#034;;<br \/>\nconst string&amp; s2 &#061; &#034;123456&#034;;<\/p>\n<p>\/\/ \u6d3e\u2f63\u7c7b\u5bf9\u8c61\u53ef\u4ee5\u8d4b\u503c\u7ed9\u57fa\u7c7b\u7684\u5bf9\u8c61\u662f\u901a\u8fc7\u8c03\u2f64\u540e\u2faf\u4f1a\u8bb2\u89e3\u7684\u57fa\u7c7b\u7684\u62f7\u2ec9\u6784\u9020\u5b8c\u6210\u7684<br \/>\nPerson pobj &#061; sobj;<\/p>\n<p>\/\/2.\u57fa\u7c7b\u5bf9\u8c61\u4e0d\u80fd\u8d4b\u503c\u7ed9\u6d3e\u2f63\u7c7b\u5bf9\u8c61&#xff0c;\u8fd9\u2fa5\u4f1a\u7f16\u8bd1\u62a5\u9519<br \/>\nsobj &#061; pobj;<\/p>\n<p>return 0;<br \/>\n} <\/p>\n<hr \/>\n<h4 id=\"%E4%B8%89%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%AD%E7%9A%84%E4%BD%9C%E7%94%A8%E5%9F%9F\">\u4e09\u3001\u7ee7\u627f\u4e2d\u7684\u4f5c\u7528\u57df<\/h4>\n<h5 id=\"3.1%20%E9%9A%90%E8%97%8F%E8%A7%84%E5%88%99\">3.1 \u9690\u85cf\u89c4\u5219<\/h5>\n<li>\u5728\u7ee7\u627f\u4f53\u7cfb\u4e2d\u57fa\u7c7b\u548c\u6d3e\u2f63\u7c7b\u90fd\u6709\u72ec\u2f74\u7684\u4f5c\u2f64\u57df\u3002<\/li>\n<li>\u6d3e\u2f63\u7c7b\u548c\u57fa\u7c7b\u4e2d\u6709\u540c\u540d\u6210\u5458&#xff0c;\u6d3e\u2f63\u7c7b\u6210\u5458\u5c06\u5c4f\u853d\u57fa\u7c7b\u5bf9\u540c\u540d\u6210\u5458\u7684\u76f4\u63a5\u8bbf\u95ee&#xff0c;\u8fd9\u79cd\u60c5\u51b5\u53eb\u9690\u85cf\u3002 &#xff08;\u5728\u6d3e\u2f63\u7c7b\u6210\u5458\u51fd\u6570\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u2f64 <span style=\"color:#4da8ee\">\u57fa\u7c7b::\u57fa\u7c7b\u6210\u5458<\/span> \u663e\u2f70\u8bbf\u95ee&#xff09;<\/li>\n<li>\u9700\u8981\u6ce8\u610f\u7684\u662f\u5982\u679c\u662f\u6210\u5458\u51fd\u6570\u7684\u9690\u85cf&#xff0c;\u53ea\u9700\u8981\u51fd\u6570\u540d\u76f8\u540c\u5c31\u6784\u6210\u9690\u85cf\u3002<\/li>\n<li>\u6ce8\u610f\u5728\u5b9e\u9645\u4e2d\u5728\u7ee7\u627f\u4f53\u7cfb\u2fa5\u2faf\u6700\u597d\u4e0d\u8981\u5b9a\u4e49\u540c\u540d\u7684\u6210\u5458\u3002<\/li>\n<p>\u4e0b\u9762\u5c31\u662f\u4e0a\u9762\u7b2c\u4e8c\u70b9\u4e2d\u9610\u8ff0\u7684\u573a\u666f&#xff0c;\u5f53\u57fa\u7c7b\u548c\u6d3e\u751f\u7c7b\u4e2d\u6709\u540c\u540d\u6210\u5458\u53d8\u91cf&#xff0c;\u90a3\u4e48\u6d3e\u751f\u7c7b\u4e2d\u7684\u6210\u5458\u51fd\u6570\u8bbf\u95ee\u7684\u540c\u540d\u53d8\u91cf\u662f\u57fa\u7c7b\u4e2d\u7684\u8fd8\u662f\u6d3e\u751f\u7c7b\u4e2d\u7684\u5462&#xff1f;\u7b54\u6848\u662f\u6d3e\u751f\u7c7b\u3002<span style=\"color:#4da8ee\">\u5148\u5230\u6d3e\u751f\u7c7b\u4e2d\u53bb\u627e&#xff0c;\u518d\u5230\u57fa\u7c7b\u4e2d\u53bb\u627e&#xff0c;\u518d\u5230\u5168\u5c40\u57df\u4e2d\u53bb\u5bfb\u627e\u3002<\/span><\/p>\n<p>class Person<br \/>\n{<br \/>\nprotected:<br \/>\nstring _name; \/\/\u59d3\u540d<br \/>\nint _num &#061; 456;     \/\/\u8eab\u4efd\u8bc1\u53f7<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\nprotected:<br \/>\nint _num &#061; 123;  \/\/\u5b66\u53f7<\/p>\n<p>public:<br \/>\nvoid Print()<br \/>\n{<br \/>\ncout &lt;&lt; _num &lt;&lt; endl;\/\/\u8fd9\u91cc\u8bbf\u95ee\u7684\u662f\u54ea\u4e2a_num?\u6d3e\u751f\u7c7b\u4e2d\u7684<br \/>\n        \/\/\u5728\u6d3e\u2f63\u7c7b\u6210\u5458\u51fd\u6570\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u2f64 \u57fa\u7c7b::\u57fa\u7c7b\u6210\u5458 \u663e\u2f70\u8bbf\u95ee<br \/>\n        cout &lt;&lt; Person::_num &lt;&lt; endl;\/\/\u8fd9\u6837\u5c31\u53ef\u4ee5\u8bbf\u95ee\u5230\u57fa\u7c7b\u7684_num<br \/>\n}<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\nStudent s;<br \/>\ns.Print();<\/p>\n<p>return 0;<br \/>\n} <\/p>\n<h5 id=\"3.2%20%E8%80%83%E5%AF%9F%E7%BB%A7%E6%89%BF%E4%BD%9C%E7%94%A8%E5%9F%9F%E7%9B%B8%E5%85%B3%E9%80%89%E6%8B%A9%E9%A2%98\">3.2 \u8003\u5bdf\u7ee7\u627f\u4f5c\u7528\u57df\u76f8\u5173\u9009\u62e9\u9898<\/h5>\n<h6 id=\"%E3%80%90A%E5%92%8CB%E7%B1%BB%E4%B8%AD%E7%9A%84%E4%B8%A4%E4%B8%AAfun%E6%9E%84%E6%88%90%E4%BB%80%E4%B9%88%E5%85%B3%E7%B3%BB%EF%BC%88%EF%BC%89%E3%80%91\">\u3010A\u548cB\u7c7b\u4e2d\u7684\u4e24\u4e2afun\u6784\u6210\u4ec0\u4e48\u5173\u7cfb&#xff08;&#xff09;\u3011<\/h6>\n<p>A. \u91cd\u8f7d B. \u9690\u85cf C.\u6ca1\u5173\u7cfb<\/p>\n<p>B\u3002\u89e3\u6790&#xff1a;\u91cd\u8f7d\u8981\u6c42\u5728\u540c\u4e00\u4e2a\u4f5c\u7528\u57df&#xff0c;\u8fd9\u91cc\u89c1\u4e0a\u9762\u7b2c\u4e09\u70b9&#xff0c;\u5982\u679c\u662f\u6210\u5458\u51fd\u6570\u7684\u9690\u85cf&#xff0c;\u53ea\u9700\u8981<span style=\"color:#4da8ee\">\u51fd\u6570\u540d\u76f8\u540c<\/span>\u5c31\u6784\u6210\u9690\u85cf\u3002<\/p>\n<h6 id=\"%E3%80%90%E4%B8%8B%E2%BE%AF%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%BC%96%E8%AF%91%E8%BF%90%E2%BE%8F%E7%BB%93%E6%9E%9C%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%88%EF%BC%89%E3%80%91\">\u3010\u4e0b\u2faf\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fd0\u2f8f\u7ed3\u679c\u662f\u4ec0\u4e48&#xff08;&#xff09;\u3011<\/h6>\n<p>A. \u7f16\u8bd1\u62a5\u9519 B. \u8fd0\u2f8f\u62a5\u9519 C. \u6b63\u5e38\u8fd0\u2f8f<\/p>\n<p>A\u3002\u89e3\u6790&#xff1a;\u57fa\u7c7b\u548c\u6d3e\u751f\u7c7b\u91cc\u9762\u7684\u540c\u540d\u51fd\u6570\u6784\u6210\u4e86\u9690\u85cf\u5173\u7cfb&#xff0c;\u6d3e\u2f63\u7c7b\u6210\u5458fun\u51fd\u6570\u5c06\u5c4f\u853d\u57fa\u7c7b\u5bf9\u540c\u540d\u6210\u5458\u7684\u76f4\u63a5\u8bbf\u95ee&#xff0c;\u5c31\u8c03\u4e0d\u5230\u57fa\u7c7b\u91cc\u9762\u7684fun\u51fd\u6570&#xff0c;\u6ca1\u6709\u4f20\u53c2&#xff0c;\u5c31\u662f\u7f16\u8bd1\u62a5\u9519&#xff08;\u8bed\u6cd5\u9519\u8bef&#xff09;\u3002b.A::fun();\u8fd9\u91cc\u6307\u5b9a\u7c7b\u57df\u5c31\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u4e86<\/p>\n<p>class A<br \/>\n{<br \/>\npublic:<br \/>\nvoid fun()<br \/>\n{<br \/>\ncout &lt;&lt; &#034;func()&#034; &lt;&lt; endl;<br \/>\n}<br \/>\n};<br \/>\nclass B : public A<br \/>\n{<br \/>\npublic:<br \/>\nvoid fun(int i)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;func(int i)&#034; &lt;&lt; i &lt;&lt; endl;<br \/>\n}<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\nB b;<br \/>\nb.fun(10);<br \/>\nb.fun();<\/p>\n<p>return 0;<br \/>\n}; <\/p>\n<hr \/>\n<h4 id=\"%E5%9B%9B%E3%80%81%E6%B4%BE%E2%BD%A3%E7%B1%BB%E7%9A%84%E9%BB%98%E8%AE%A4%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0\">\u56db\u3001\u6d3e\u2f63\u7c7b\u7684\u9ed8\u8ba4\u6210\u5458\u51fd\u6570<\/h4>\n<h5 id=\"4.1%C2%A04%E4%B8%AA%E5%B8%B8%E2%BB%85%E9%BB%98%E8%AE%A4%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0\">4.1\u00a04\u4e2a\u5e38\u2ec5\u9ed8\u8ba4\u6210\u5458\u51fd\u6570<\/h5>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"330\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201801-68892c7971151.png\" width=\"800\" \/><\/p>\n<p>6\u4e2a\u9ed8\u8ba4\u6210\u5458\u51fd\u6570&#xff0c;\u9ed8\u8ba4\u7684\u610f\u601d\u5c31\u662f\u6307\u6211\u4eec\u4e0d\u5199&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u53d8\u6211\u4eec\u2f83\u52a8\u2f63\u6210\u2f00\u4e2a&#xff0c;\u90a3\u4e48\u5728\u6d3e\u2f63\u7c7b\u4e2d&#xff0c;\u8fd9\u2f0f\u4e2a\u6210\u5458\u51fd\u6570\u662f\u5982\u4f55\u2f63\u6210\u7684\u5462&#xff1f;<\/p>\n<li>\u6d3e\u2f63\u7c7b\u7684\u6784\u9020\u51fd\u6570\u5fc5\u987b\u8c03\u2f64\u57fa\u7c7b\u7684\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316\u57fa\u7c7b\u7684\u90a3\u2f00\u90e8\u5206\u6210\u5458\u3002\u5982\u679c\u57fa\u7c7b\u6ca1\u6709\u9ed8\u8ba4\u7684\u6784\u9020\u51fd\u6570&#xff0c;\u5219\u5fc5\u987b\u5728\u6d3e\u2f63\u7c7b\u6784\u9020\u51fd\u6570\u7684\u521d\u59cb\u5316\u5217\u8868\u9636\u6bb5\u663e\u2f70\u8c03\u2f64\u3002<\/li>\n<li>\u6d3e\u2f63\u7c7b\u7684\u62f7\u2ec9\u6784\u9020\u51fd\u6570\u5fc5\u987b\u8c03\u2f64\u57fa\u7c7b\u7684\u62f7\u2ec9\u6784\u9020\u5b8c\u6210\u57fa\u7c7b\u7684\u62f7\u2ec9\u521d\u59cb\u5316\u3002<\/li>\n<li>\u6d3e\u2f63\u7c7b\u7684operator&#061;\u5fc5\u987b\u8981\u8c03\u2f64\u57fa\u7c7b\u7684operator&#061;\u5b8c\u6210\u57fa\u7c7b\u7684\u590d\u5236\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\u6d3e\u2f63\u7c7b\u7684 operator&#061;\u9690\u85cf\u4e86\u57fa\u7c7b\u7684operator&#061;&#xff0c;\u6240\u4ee5\u663e\u2f70\u8c03\u2f64\u57fa\u7c7b\u7684operator&#061;&#xff0c;\u9700\u8981\u6307\u5b9a\u57fa\u7c7b\u4f5c\u2f64\u57df<\/li>\n<li>\u6d3e\u2f63\u7c7b\u7684\u6790\u6784\u51fd\u6570\u4f1a\u5728\u88ab\u8c03\u2f64\u5b8c\u6210\u540e\u2f83\u52a8\u8c03\u2f64\u57fa\u7c7b\u7684\u6790\u6784\u51fd\u6570\u6e05\u7406\u57fa\u7c7b\u6210\u5458\u3002\u56e0\u4e3a\u8fd9\u6837\u624d\u80fd\u4fdd\u8bc1\u6d3e \u2f63\u7c7b\u5bf9\u8c61\u5148\u6e05\u7406\u6d3e\u2f63\u7c7b\u6210\u5458\u518d\u6e05\u7406\u57fa\u7c7b\u6210\u5458\u7684\u987a\u5e8f\u3002<\/li>\n<li>\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u521d\u59cb\u5316\u5148\u8c03\u2f64\u57fa\u7c7b\u6784\u9020\u518d\u8c03\u6d3e\u2f63\u7c7b\u6784\u9020\u3002<\/li>\n<li>\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u6790\u6784\u6e05\u7406\u5148\u8c03\u2f64\u6d3e\u2f63\u7c7b\u6790\u6784\u518d\u8c03\u57fa\u7c7b\u7684\u6790\u6784\u3002<\/li>\n<li>\u56e0\u4e3a\u591a\u6001\u4e2d\u2f00\u4e9b\u573a\u666f\u6790\u6784\u51fd\u6570\u9700\u8981\u6784\u6210\u91cd\u5199&#xff0c;\u91cd\u5199\u7684\u6761\u4ef6\u4e4b\u2f00\u662f\u51fd\u6570\u540d\u76f8\u540c(\u8fd9\u4e2a\u6211\u4eec\u591a\u6001\u7ae0\u8282\u4f1a\u8bb2 \u89e3)\u3002\u90a3\u4e48\u7f16\u8bd1\u5668\u4f1a\u5bf9\u6790\u6784\u51fd\u6570\u540d\u8fdb\u2f8f\u7279\u6b8a\u5904\u7406&#xff0c;\u5904\u7406\u6210destructor()&#xff0c;\u6240\u4ee5\u57fa\u7c7b\u6790\u6784\u51fd\u6570\u4e0d\u52a0 virtual\u7684\u60c5\u51b5\u4e0b&#xff0c;\u6d3e\u2f63\u7c7b\u6790\u6784\u51fd\u6570\u548c\u57fa\u7c7b\u6790\u6784\u51fd\u6570\u6784\u6210\u9690\u85cf\u5173\u7cfb\u3002<\/li>\n<h6 id=\"%E3%80%90%E6%9C%89%E5%85%B3%E4%B8%8A%E9%9D%A2%E7%AC%AC%E5%9B%9B%E7%82%B9%E3%80%91%C2%A0\">\u3010\u6709\u5173\u4e0a\u9762\u7b2c\u56db\u70b9\u3011\u00a0<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1527\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201802-68892c7a727c5.png\" width=\"2607\" \/><\/p>\n<p>#include&lt;iostream&gt;<br \/>\n#include&lt;string&gt;<\/p>\n<p>using namespace std;<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\nPerson(const char* name)<br \/>\n:_name(name)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Person()&#034; &lt;&lt; endl;<br \/>\n}<\/p>\n<p>Person(const Person&amp; p)<br \/>\n:_name(p._name)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Person(const Person&amp; p)&#034; &lt;&lt; endl;<br \/>\n}<\/p>\n<p>Person&amp; operator&#061;(const Person&amp; p)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Person&amp; operator&#061;(const Person&amp; p)&#034; &lt;&lt; endl;<br \/>\nif (this !&#061; &amp;p)<br \/>\n_name &#061; p._name;<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>~Person()<br \/>\n{<br \/>\ncout &lt;&lt; &#034;~Person()&#034; &lt;&lt; endl;<br \/>\n}<\/p>\n<p>protected:<br \/>\nstring _name; \/\/\u59d3\u540d<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\nStudent(int num,string address,const char* name)\/\/\u4e0b\u9762\u662f\u6309\u58f0\u660e\u7684\u987a\u5e8f\u8fdb\u884c\u521d\u59cb\u5316\u7684&#xff0c;\u6700\u5148\u521d\u59cb\u5316\u7684\u5c31\u662fPerson&#xff0c;\u518d\u662f\u6309\u58f0\u660e\u7684\u987a\u5e8f<br \/>\n:_num(num)<br \/>\n,_address(address)<br \/>\n,Person(name)\/\/\u8fd9\u91cc\u5c06\u7236\u7c7b\u5f53\u505a\u4e00\u4e2a\u6574\u4f53<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Student()&#034; &lt;&lt; endl;<br \/>\n}<\/p>\n<p>Student(const Student&amp; s)<br \/>\n\/\/\u6b64\u5904\u8c03\u7528\u7684\u662f\u7236\u7c7b\u7684\u62f7\u8d1d\u6784\u9020&#xff0c;\u4f20\u7684\u662f\u4e00\u6574\u4e2a\u5b50\u7c7b&#xff0c;\u5176\u5b9e\u6211\u4eec\u5e94\u8be5\u50cf\u4e0a\u9762\u90a3\u6837\u4f20\u5c5e\u4e8e\u7236\u7c7b\u7684\u90a3\u4e00\u90e8\u5206&#xff0c;\u4f46\u662f\u8fd9\u91cc\u5e94\u7528\u4e86\u6211\u4eec\u524d\u9762\u5b66\u7684\u5207\u7247<br \/>\n\/\/\u5c06\u6d3e\u751f\u7c7b\u5bf9\u8c61\u8d4b\u503c\u7ed9\u57fa\u7c7b\u7684\u5f15\u7528&#xff0c;\u81ea\u52a8\u5207\u5c5e\u4e8e\u57fa\u7c7b\u7684\u90a3\u4e00\u90e8\u5206<br \/>\n:Person(s)<br \/>\n,_num(s._num)<br \/>\n,_address(s._address)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Student(const Student&amp; s)&#034; &lt;&lt; endl;<br \/>\n}<\/p>\n<p>Student&amp; operator&#061;(const Student&amp; s)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Student&amp; operator&#061;(const Student&amp; s)&#034; &lt;&lt; endl;<br \/>\nif (this !&#061; &amp;s)<br \/>\n{<br \/>\n_num &#061; s._num;<br \/>\n_address &#061; s._address;<br \/>\nPerson::operator&#061;(s);\/\/\u8fd9\u91cc\u548c\u57fa\u7c7b\u4e2d\u6210\u5458\u51fd\u6570\u540c\u540d&#xff0c;\u6784\u6210\u9690\u85cf\u5173\u7cfb&#xff0c;\u9700\u8981\u663e\u793a\u58f0\u660e\u7c7b\u57df<br \/>\n}<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>~Student()<br \/>\n{<br \/>\ncout &lt;&lt; &#034;~Student()&#034; &lt;&lt; endl;<br \/>\n\/\/\u8fd9\u91cc\u51fa\u73b0\u4e86\u62a5\u9519&#xff0c;\u56e0\u4e3a\u5176\u4ed6\u7684\u4e00\u4e9b\u539f\u56e0&#xff0c;\u8fd9\u91cc\u7684\u6790\u6784\u51fd\u6570\u4f1a\u88ab\u7f16\u8bd1\u6210destructor()&#xff0c;\u5c31\u548c\u57fa\u7c7b\u7684destructor()\u6784\u6210\u4e86\u9690\u85cf\u5173\u7cfb<br \/>\n\/\/~Person();<br \/>\n}<\/p>\n<p>protected:<br \/>\nint _num;\/\/\u5b66\u53f7<br \/>\nstring _address;\/\/\u5730\u5740<\/p>\n<p>};<\/p>\n<p>\/\/\u8981\u70b9<br \/>\n\/\/\u6211\u4eec\u4e0d\u5199&#xff0c;\u7f16\u8bd1\u5668\u9ed8\u8ba4\u751f\u6210\u7684\u884c\u4e3a\u662f\u4ec0\u4e48&#xff1f;<br \/>\n\/\/\u9ed8\u8ba4\u751f\u6210\u4e0d\u7b26\u5408\u6211\u4eec\u7684\u8981\u6c42&#xff0c;\u81ea\u5df1\u5199&#xff0c;\u5f97\u600e\u4e48\u5199&#xff1f;<\/p>\n<p>\/\/\u7279\u70b9&#xff1a;\u628a\u5b50\u7c7b\u4e2d\u7ee7\u627f\u4e0b\u6765\u7684\u7236\u7c7b\u6210\u5458\u5f53\u505a\u4e00\u4e2a\u6574\u4f53\u5bf9\u8c61<\/p>\n<p>\/\/\u6784\u9020<br \/>\n\/\/\u9ed8\u8ba4&#xff1a;\u5b50\u7c7b\u6210\u5458 \u5185\u7f6e\u7c7b\u578b(\u6709\u7f3a\u7701\u503c\u5c31\u7528&#xff0c;\u6ca1\u6709\u5c31\u4e0d\u786e\u5b9a)\u548c\u81ea\u5b9a\u4e49\u7c7b\u578b(\u9ed8\u8ba4\u6784\u9020) &#043; \u7236\u7c7b\u6210\u5458(\u5fc5\u987b\u8c03\u7528\u7236\u7c7b\u9ed8\u8ba4\u6784\u9020)<\/p>\n<p>\/\/\u62f7\u8d1d\u6784\u9020&#xff0c;\u9ed8\u8ba4\u751f\u6210\u7684\u5c31\u591f\u7528\u4e0d\u7528\u81ea\u5df1\u5199<br \/>\n\/\/\u9ed8\u8ba4&#xff1a;\u5b50\u7c7b\u6210\u5458 \u5185\u7f6e\u7c7b\u578b(\u503c\u62f7\u8d1d)\u548c\u81ea\u5b9a\u4e49\u7c7b\u578b(\u8c03\u7528\u5b83\u7684\u62f7\u8d1d\u6784\u9020) &#043; \u7236\u7c7b\u6210\u5458(\u8c03\u7528\u7236\u7c7b\u62f7\u8d1d\u6784\u9020)<\/p>\n<p>\/\/\u8d4b\u503c\u91cd\u8f7d&#xff0c;\u7c7b\u4f3c\u4e8e\u62f7\u8d1d\u6784\u9020&#xff0c;\u9ed8\u8ba4\u751f\u6210\u7684\u884c\u4e3a\u5c31OK<\/p>\n<p>\/\/\u6790\u6784<br \/>\n\/\/\u9ed8\u8ba4&#xff1a;\u5b50\u7c7b\u6210\u5458 \u5185\u7f6e\u7c7b\u578b&#xff08;\u4e0d\u5904\u7406&#xff09;\u548c\u81ea\u5b9a\u4e49\u7c7b\u578b&#xff08;\u8c03\u7528\u5b83\u7684\u6790\u6784&#xff09;&#043; \u7236\u7c7b\u6210\u5458&#xff08;\u8c03\u7528\u5b83\u7684\u6790\u6784&#xff09;<br \/>\n\/\/\u81ea\u5df1\u5b9e\u73b0\u7684\u8bdd&#xff0c;\u6ce8\u610f\u4e0d\u9700\u8981\u663e\u793a\u8c03\u7528\u7236\u7c7b\u6790\u6784&#xff0c;\u5b50\u7c7b\u6790\u6784\u51fd\u6570\u7ed3\u675f\u540e&#xff0c;\u4f1a\u81ea\u52a8\u8c03\u7528\u7236\u7c7b\u6790\u6784<\/p>\n<p>int main()<br \/>\n{<br \/>\nStudent s1(20, &#034;\u738b\u4e94&#034;, &#034;\u5317\u4eac&#034;);<br \/>\nStudent s2(s1);\/\/\u62f7\u8d1d\u6784\u9020<\/p>\n<p>Student s3 &#061; s2;<\/p>\n<p>return 0;<br \/>\n} <\/p>\n<h5 id=\"4.2%C2%A0%E5%AE%9E%E7%8E%B0%E2%BC%80%E4%B8%AA%E4%B8%8D%E8%83%BD%E8%A2%AB%E7%BB%A7%E6%89%BF%E7%9A%84%E7%B1%BB\">4.2\u00a0\u5b9e\u73b0\u2f00\u4e2a\u4e0d\u80fd\u88ab\u7ee7\u627f\u7684\u7c7b<\/h5>\n<p><span style=\"color:#333333\">\u2f45\u6cd51&#xff1a;\u57fa\u7c7b\u7684\u6784\u9020\u51fd\u6570\u79c1\u6709&#xff0c;\u6d3e\u2f63\u7c7b\u7684\u6784\u6210\u5fc5\u987b\u8c03\u2f64\u57fa\u7c7b\u7684\u6784\u9020\u51fd\u6570&#xff0c;\u4f46\u662f\u57fa\u7c7b\u7684\u6784\u6210\u51fd\u6570\u79c1\u6709\u5316\u4ee5\u540e&#xff0c;\u6d3e\u2f63\u7c7b\u770b\u4e0d\u2ec5\u5c31\u4e0d\u80fd\u8c03\u2f64\u4e86&#xff0c;\u90a3\u4e48\u6d3e\u2f63\u7c7b\u5c31\u2f46\u6cd5\u5b9e\u4f8b\u5316\u51fa\u5bf9\u8c61\u3002 <\/span><\/p>\n<p>class Base<br \/>\n{<br \/>\npublic:<br \/>\nvoid func5() { cout &lt;&lt; &#034;Base::func5&#034; &lt;&lt; endl; }<br \/>\nprotected:<br \/>\nint a &#061; 1;<br \/>\nprivate:<br \/>\n\/\/ C&#043;&#043;98\u7684\u2f45\u6cd5<br \/>\nBase()<br \/>\n{}<br \/>\n};<\/p>\n<p>class Derive :public Base<br \/>\n{<br \/>\nvoid func4() { cout &lt;&lt; &#034;Derive::func4&#034; &lt;&lt; endl; }<br \/>\nprotected:<br \/>\nint b &#061; 2;<br \/>\n};<br \/>\nint main()<br \/>\n{<br \/>\nBase b;<br \/>\nDerive d;<br \/>\nreturn 0;<br \/>\n} <\/p>\n<p><span style=\"color:#333333\">\u2f45\u6cd52&#xff1a;C&#043;&#043;11\u65b0\u589e\u4e86\u2f00\u4e2afinal\u5173\u952e\u5b57&#xff0c;final\u4fee\u6539\u57fa\u7c7b&#xff0c;\u6d3e\u2f63\u7c7b\u5c31\u4e0d\u80fd\u7ee7\u627f\u4e86\u3002<\/span><\/p>\n<p>class Base final<br \/>\n{<br \/>\npublic:<br \/>\nvoid func5()<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Base::func5&#034; &lt;&lt; endl;<br \/>\n}<\/p>\n<p>Base()<br \/>\n{ }<\/p>\n<p>protected:<br \/>\nint a &#061; 1;<\/p>\n<p>};<\/p>\n<p>class Derive :public Base<br \/>\n{<br \/>\nvoid func4() { cout &lt;&lt; &#034;Derive::func4&#034; &lt;&lt; endl; }<br \/>\nprotected:<br \/>\nint b &#061; 2;<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\nBase b;<br \/>\nDerive d;<br \/>\nreturn 0;<br \/>\n} <\/p>\n<hr \/>\n<h4 id=\"%E4%BA%94%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%8E%E5%8F%8B%E5%85%83\">\u4e94\u3001\u7ee7\u627f\u4e0e\u53cb\u5143<\/h4>\n<p>\u53cb\u5143\u5173\u7cfb\u4e0d\u80fd\u7ee7\u627f&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u57fa\u7c7b\u53cb\u5143\u4e0d\u80fd\u8bbf\u95ee\u6d3e\u2f63\u7c7b\u79c1\u6709\u548c\u4fdd\u62a4\u6210\u5458\u3002<\/p>\n<p>class Student;<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\nfriend void Display(const Person&amp; p, const Student&amp; s);<br \/>\nprotected:<br \/>\nstring _name; \/\/ \u59d3\u540d<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\nfriend void Display(const Person&amp; p, const Student&amp; s);<br \/>\nprotected:<br \/>\nint _stuNum; \/\/ \u5b66\u53f7<br \/>\n};<\/p>\n<p>void Display(const Person&amp; p, const Student&amp; s)<br \/>\n{<br \/>\ncout &lt;&lt; p._name &lt;&lt; endl;<br \/>\ncout &lt;&lt; s._stuNum &lt;&lt; endl;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\nPerson p;<br \/>\nStudent s;<br \/>\n\/\/ \u7f16\u8bd1\u62a5\u9519&#xff1a;error C2248: \u201cStudent::_stuNum\u201d: \u2f46\u6cd5\u8bbf\u95ee protected \u6210\u5458<br \/>\n\/\/ \u89e3\u51b3\u2f45\u6848&#xff1a;Display\u4e5f\u53d8\u6210Student \u7684\u53cb\u5143\u5373\u53ef<br \/>\nDisplay(p, s);<br \/>\nreturn 0;<br \/>\n} <\/p>\n<hr \/>\n<h4 id=\"%E5%85%AD%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%8E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98\">\u516d\u3001\u7ee7\u627f\u4e0e\u9759\u6001\u6210\u5458<\/h4>\n<p>\u57fa\u7c7b\u5b9a\u4e49\u4e86static\u9759\u6001\u6210\u5458&#xff0c;\u5219\u6574\u4e2a\u7ee7\u627f\u4f53\u7cfb\u2fa5\u2faf\u53ea\u6709\u2f00\u4e2a\u8fd9\u6837\u7684\u6210\u5458\u3002\u2f46\u8bba\u6d3e\u2f63\u51fa\u591a\u5c11\u4e2a\u6d3e\u2f63\u7c7b&#xff0c;\u90fd \u53ea\u6709\u2f00\u4e2astatic\u6210\u5458\u5b9e\u4f8b\u3002<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\nstring _name;<br \/>\nstatic int _count;<br \/>\n};<br \/>\nint Person::_count &#061; 0;<br \/>\nclass Student : public Person<br \/>\n{<br \/>\nprotected:<br \/>\nint _stuNum;<br \/>\n};<br \/>\nint main()<br \/>\n{<br \/>\nPerson p;<br \/>\nStudent s;<br \/>\n\/\/ \u8fd9\u2fa5\u7684\u8fd0\u2f8f\u7ed3\u679c\u53ef\u4ee5\u770b\u5230\u2fae\u9759\u6001\u6210\u5458_name\u7684\u5730\u5740\u662f\u4e0d\u2f00\u6837\u7684<br \/>\n\/\/ \u8bf4\u660e\u6d3e\u2f63\u7c7b\u7ee7\u627f\u4e0b\u6765\u4e86&#xff0c;\u2f57\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u5404\u6709\u2f00\u4efd<br \/>\ncout &lt;&lt; &amp;p._name &lt;&lt; endl;<br \/>\ncout &lt;&lt; &amp;s._name &lt;&lt; endl;<\/p>\n<p>\/\/ \u8fd9\u2fa5\u7684\u8fd0\u2f8f\u7ed3\u679c\u53ef\u4ee5\u770b\u5230\u9759\u6001\u6210\u5458_count\u7684\u5730\u5740\u662f\u2f00\u6837\u7684<br \/>\n\/\/ \u8bf4\u660e\u6d3e\u2f63\u7c7b\u548c\u57fa\u7c7b\u5171\u2f64\u540c\u2f00\u4efd\u9759\u6001\u6210\u5458<br \/>\ncout &lt;&lt; &amp;p._count &lt;&lt; endl;<br \/>\ncout &lt;&lt; &amp;s._count &lt;&lt; endl;<\/p>\n<p>\/\/ \u516c\u6709\u7684\u60c5\u51b5\u4e0b&#xff0c;\u2f57\u6d3e\u2f63\u7c7b\u6307\u5b9a\u7c7b\u57df\u90fd\u53ef\u4ee5\u8bbf\u95ee\u9759\u6001\u6210\u5458<br \/>\ncout &lt;&lt; Person::_count &lt;&lt; endl;<br \/>\ncout &lt;&lt; Student::_count &lt;&lt; endl;<\/p>\n<p>return 0;<br \/>\n} <\/p>\n<hr \/>\n<h4 id=\"%C2%A0%E4%B8%83%E3%80%81%E5%A4%9A%E7%BB%A7%E6%89%BF%E5%8F%8A%E5%85%B6%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF%E9%97%AE%E9%A2%98\">\u4e03\u3001\u591a\u7ee7\u627f\u53ca\u5176\u83f1\u5f62\u7ee7\u627f\u95ee\u9898<\/h4>\n<h5 id=\"7.1%C2%A0%E7%BB%A7%E6%89%BF%E6%A8%A1%E5%9E%8B\">7.1\u00a0\u7ee7\u627f\u6a21\u578b<\/h5>\n<p>\u5355\u7ee7\u627f&#xff1a;\u2f00\u4e2a\u6d3e\u2f63\u7c7b<span style=\"color:#4da8ee\">\u53ea\u6709\u2f00\u4e2a\u76f4\u63a5\u57fa\u7c7b<\/span>\u65f6\u79f0\u8fd9\u4e2a\u7ee7\u627f\u5173\u7cfb\u4e3a\u5355\u7ee7\u627f<\/p>\n<p>\u591a\u7ee7\u627f&#xff1a;\u2f00\u4e2a\u6d3e\u2f63\u7c7b<span style=\"color:#4da8ee\">\u6709\u4e24\u4e2a\u6216\u4ee5\u4e0a\u76f4\u63a5\u57fa\u7c7b\u65f6<\/span>\u79f0\u8fd9\u4e2a\u7ee7\u627f\u5173\u7cfb\u4e3a\u591a\u7ee7\u627f&#xff0c;\u591a\u7ee7\u627f\u5bf9\u8c61\u5728\u5185\u5b58\u4e2d\u7684\u6a21\u578b\u662f&#xff0c;\u5148\u7ee7\u627f\u7684\u57fa\u7c7b\u5728\u524d\u2faf&#xff0c;\u540e\u2faf\u7ee7\u627f\u7684\u57fa\u7c7b\u5728\u540e\u2faf&#xff0c;\u6d3e\u2f63\u7c7b\u6210\u5458\u5728\u653e\u5230\u6700\u540e\u2faf\u3002<\/p>\n<p>\u83f1\u5f62\u7ee7\u627f&#xff1a;\u83f1\u5f62\u7ee7\u627f\u662f\u591a\u7ee7\u627f\u7684\u2f00\u79cd\u7279\u6b8a\u60c5\u51b5\u3002\u83f1\u5f62\u7ee7\u627f\u7684\u95ee\u9898&#xff0c;\u4ece\u4e0b\u2faf\u7684\u5bf9\u8c61\u6210\u5458\u6a21\u578b\u6784\u9020&#xff0c;\u53ef\u4ee5\u770b\u51fa\u83f1\u5f62\u7ee7\u627f\u6709<span style=\"color:#4da8ee\">\u6570\u636e\u5197\u4f59&#xff08;\u5b58\u5728\u4e24\u4efd&#xff0c;\u6d6a\u8d39\u7a7a\u95f4&#xff09;\u548c\u4e8c\u4e49\u6027&#xff08;\u8bbf\u95ee\u7684\u65f6\u5019\u4e0d\u77e5\u9053\u8bbf\u95ee\u7684\u662f\u8c01&#xff09;<\/span>\u7684\u95ee\u9898&#xff0c;\u5728Assistant\u7684\u5bf9\u8c61\u4e2dPerson\u6210\u5458\u4f1a\u6709\u4e24\u4efd\u3002\u2f40\u6301\u591a\u7ee7\u627f\u5c31 \u2f00\u5b9a\u4f1a\u6709\u83f1\u5f62\u7ee7\u627f&#xff0c;\u50cfJava\u5c31\u76f4\u63a5\u4e0d\u2f40\u6301\u591a\u7ee7\u627f&#xff0c;\u89c4\u907f\u6389\u4e86\u8fd9\u2fa5\u7684\u95ee\u9898&#xff0c;\u6240\u4ee5\u5b9e\u8df5\u4e2d\u6211\u4eec\u4e5f\u662f\u4e0d\u5efa\u8bae\u8bbe\u8ba1\u51fa\u83f1\u5f62\u7ee7\u627f\u8fd9\u6837\u7684\u6a21\u578b\u7684\u3002<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\nstring _name; \/\/ \u59d3\u540d<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\nprotected:<br \/>\nint _num; \/\/\u5b66\u53f7<br \/>\n};<\/p>\n<p>class Teacher : public Person<br \/>\n{<br \/>\nprotected:<br \/>\nint _id; \/\/ \u804c\u2f2f\u7f16\u53f7<br \/>\n};<\/p>\n<p>class Assistant : public Student, public Teacher<br \/>\n{<br \/>\nprotected:<br \/>\nstring _majorCourse; \/\/ \u4e3b\u4fee\u8bfe\u7a0b<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\nAssistant a;<br \/>\na._name &#061; &#034;peter&#034;;\/\/ \u7f16\u8bd1\u62a5\u9519&#xff1a;error C2385: \u5bf9\u201c_name\u201d\u7684\u8bbf\u95ee\u4e0d\u660e\u786e<\/p>\n<p>\/\/ \u9700\u8981\u663e\u2f70\u6307\u5b9a\u8bbf\u95ee\u54ea\u4e2a\u57fa\u7c7b\u7684\u6210\u5458\u53ef\u4ee5\u89e3\u51b3\u2f06\u4e49\u6027\u95ee\u9898&#xff0c;\u4f46\u662f\u6570\u636e\u5197\u4f59\u95ee\u9898\u2f46\u6cd5\u89e3\u51b3<br \/>\na.Student::_name &#061; &#034;xxx&#034;;<br \/>\na.Teacher::_name &#061; &#034;yyy&#034;;<br \/>\nreturn 0;<br \/>\n} <\/p>\n<h5 id=\"7.2%20%E8%99%9A%E7%BB%A7%E6%89%BF\">7.2 \u865a\u7ee7\u627f<\/h5>\n<p>\u5f88\u591a\u2f08\u8bf4C&#043;&#043;\u8bed\u6cd5\u590d\u6742&#xff0c;\u5176\u5b9e\u591a\u7ee7\u627f\u5c31\u662f\u2f00\u4e2a\u4f53\u73b0\u3002\u6709\u4e86\u591a\u7ee7\u627f&#xff0c;\u5c31\u5b58\u5728\u83f1\u5f62\u7ee7\u627f&#xff0c;\u6709\u4e86\u83f1\u5f62\u7ee7\u627f\u5c31\u6709\u83f1\u5f62\u865a\u62df\u7ee7\u627f&#xff0c;\u5e95\u5c42\u5b9e\u73b0\u5c31\u5f88\u590d\u6742&#xff0c;\u6027\u80fd\u4e5f\u4f1a\u6709\u2f00\u4e9b\u635f\u5931&#xff0c;\u6240\u4ee5\u6700\u597d\u4e0d\u8981\u8bbe\u8ba1\u51fa\u83f1\u5f62\u7ee7\u627f\u3002\u591a\u7ee7\u627f\u53ef\u4ee5\u8ba4\u4e3a\u662fC&#043;&#043;\u7684\u7f3a\u9677\u4e4b\u2f00&#xff0c;\u540e\u6765\u7684\u2f00\u4e9b\u7f16\u7a0b\u8bed\u2f94\u90fd\u6ca1\u6709\u591a\u7ee7\u627f&#xff0c;\u5982Java\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1262\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201805-68892c7dda70e.png\" width=\"1897\" \/><\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\nstring _name; \/\/ \u59d3\u540d<br \/>\n\/*int _tel;<br \/>\nint _age;<br \/>\nstring _gender;<br \/>\nstring _address;*\/<br \/>\n\/\/ &#8230;<br \/>\n};<\/p>\n<p>\/\/ \u4f7f\u2f64\u865a\u7ee7\u627fPerson\u7c7b<br \/>\nclass Student : virtual public Person<br \/>\n{<br \/>\nprotected:<br \/>\nint _num; \/\/\u5b66\u53f7<br \/>\n};<\/p>\n<p>\/\/ \u4f7f\u2f64\u865a\u7ee7\u627fPerson\u7c7b<br \/>\nclass Teacher : virtual public Person<br \/>\n{<br \/>\nprotected:<br \/>\nint _id; \/\/ \u804c\u2f2f\u7f16\u53f7<br \/>\n};<\/p>\n<p>\/\/ \u6559\u6388\u52a9\u7406<br \/>\nclass Assistant : public Student, public Teacher<br \/>\n{<br \/>\nprotected:<br \/>\nstring _majorCourse; \/\/ \u4e3b\u4fee\u8bfe\u7a0b<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n\/\/ \u4f7f\u2f64\u865a\u7ee7\u627f&#xff0c;\u53ef\u4ee5\u89e3\u51b3\u6570\u636e\u5197\u4f59\u548c\u2f06\u4e49\u6027<br \/>\nAssistant a;<br \/>\na._name &#061; &#034;peter&#034;;<br \/>\nreturn 0;<br \/>\n} <\/p>\n<h6 id=\"%C2%A0%E3%80%90%E5%B0%8F%E9%A2%98%E7%9B%AE%E3%80%91\">\u00a0\u3010\u5c0f\u9898\u76ee\u3011<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"802\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201807-68892c7f26850.png\" width=\"2608\" \/><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u8bbe\u8ba1\u51fa\u591a\u7ee7\u627f&#xff0c;\u4f46\u662f\u4e0d\u5efa\u8bae\u8bbe\u8ba1\u51fa\u83f1\u5f62\u7ee7\u627f&#xff0c;\u56e0\u4e3a\u83f1\u5f62\u865a\u62df\u7ee7\u627f\u4ee5\u540e&#xff0c;\u2f46\u8bba\u662f\u4f7f\u2f64\u8fd8\u662f\u5e95\u5c42 \u90fd\u4f1a\u590d\u6742\u5f88\u591a\u3002\u5f53\u7136\u6709\u591a\u7ee7\u627f\u8bed\u6cd5\u2f40\u6301&#xff0c;\u5c31\u2f00\u5b9a\u5b58\u5728\u4f1a\u8bbe\u8ba1\u51fa\u83f1\u5f62\u7ee7\u627f&#xff0c;\u50cfJava\u662f\u4e0d\u2f40\u6301\u591a\u7ee7\u627f\u7684&#xff0c; \u5c31\u907f\u5f00\u4e86\u83f1\u5f62\u7ee7\u627f\u3002<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\nPerson(const char* name)<br \/>\n:_name(name)<br \/>\n{}<br \/>\nstring _name; \/\/ \u59d3\u540d<br \/>\n};<\/p>\n<p>class Student : virtual public Person<br \/>\n{<br \/>\npublic:<br \/>\nStudent(const char* name, int num)<br \/>\n:Person(name)<br \/>\n, _num(num)<br \/>\n{<br \/>\n}<br \/>\nprotected:<br \/>\nint _num; \/\/\u5b66\u53f7<br \/>\n};<\/p>\n<p>class Teacher : virtual public Person<br \/>\n{<br \/>\npublic:<br \/>\nTeacher(const char* name, int id)<br \/>\n:Person(name)<br \/>\n, _id(id)<br \/>\n{<br \/>\n}<br \/>\nprotected:<br \/>\nint _id; \/\/ \u804c\u2f2f\u7f16\u53f7<br \/>\n};<\/p>\n<p>\/\/ \u4e0d\u8981\u53bb\u73a9\u83f1\u5f62\u7ee7\u627f<br \/>\nclass Assistant : public Student, public Teacher<br \/>\n{<br \/>\npublic:<br \/>\nAssistant(const char* name1, const char* name2, const char* name3)<br \/>\n:Person(name3)<br \/>\n, Student(name1, 1)<br \/>\n, Teacher(name2, 2)<br \/>\n{<br \/>\n}<br \/>\nprotected:<br \/>\nstring _majorCourse; \/\/ \u4e3b\u4fee\u8bfe\u7a0b<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n\/\/ \u601d\u8003\u2f00\u4e0b\u8fd9\u2fa5a\u5bf9\u8c61\u4e2d_name\u662f&#034;\u5f20\u4e09&#034;, &#034;\u674e\u56db&#034;, &#034;\u738b\u4e94&#034;\u4e2d\u7684\u54ea\u2f00\u4e2a&#xff1f;<br \/>\nAssistant a(&#034;\u5f20\u4e09&#034;, &#034;\u674e\u56db&#034;, &#034;\u738b\u4e94&#034;);<br \/>\nreturn 0;<br \/>\n} <\/p>\n<p>\u00a0\u57fa\u7c7bPerson\u672c\u8eab&#xff0c;Student\u91cc\u9762\u7684\u57fa\u7c7bPerson&#xff0c;Teacher\u91cc\u9762\u7684\u57fa\u7c7bPerson&#xff0c;\u4e09\u4e2a\u90fd\u521d\u59cb\u5316\u5417&#xff1f;\u4e0d\u662f&#xff0c;\u53ea\u521d\u59cb\u5316\u539f\u672c\u7684Person\u2014\u201c\u738b\u4e94\u201d<\/p>\n<h5 id=\"7.3%C2%A0%E5%A4%9A%E7%BB%A7%E6%89%BF%E4%B8%AD%E6%8C%87%E9%92%88%E5%81%8F%E7%A7%BB%E9%97%AE%E9%A2%98%EF%BC%9F\">7.3\u00a0\u591a\u7ee7\u627f\u4e2d\u6307\u9488\u504f\u79fb\u95ee\u9898&#xff1f;<\/h5>\n<p>\u4e0b\u9762\u8bf4\u6cd5\u6b63\u786e\u7684\u662f&#xff08;&#xff09;<\/p>\n<p>A&#xff1a;p1 &#061;&#061; p2 &#061;&#061; p3 B&#xff1a;p1 &lt; p2 &lt; p3 C&#xff1a;p1 &#061;&#061; p3 !&#061; p2 D&#xff1a;p1 !&#061; p2 !&#061; p3<\/p>\n<p>class Base1<br \/>\n{<br \/>\n    public: int _b1;<br \/>\n};<\/p>\n<p>class Base2<br \/>\n{<br \/>\n    public: int _b2;<br \/>\n};<\/p>\n<p>class Derive : public Base1, public Base2<br \/>\n{<br \/>\n    public: int _d;<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\nDerive d;<br \/>\nBase1* p1 &#061; &amp;d;<br \/>\nBase2* p2 &#061; &amp;d;<br \/>\nDerive* p3 &#061; &amp;d;<\/p>\n<p>return 0;<br \/>\n}<\/p>\n<p>\u3010\u89e3\u6790\u3011\u00a0<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"670\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201808-68892c80ba70c.png\" width=\"2004\" \/><\/p>\n<h5 id=\"7.4%C2%A0IO%E5%BA%93%E4%B8%AD%E7%9A%84%E8%8F%B1%E5%BD%A2%E8%99%9A%E6%8B%9F%E7%BB%A7%E6%89%BF\">7.4\u00a0IO\u5e93\u4e2d\u7684\u83f1\u5f62\u865a\u62df\u7ee7\u627f<\/h5>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"341\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201809-68892c814b2a6.png\" width=\"600\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"545\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201809-68892c81a3bda.png\" width=\"800\" \/><\/p>\n<p>template&lt;class CharT, class Traits &#061; std::char_traits&lt;CharT&gt;&gt;<br \/>\nclass basic_ostream : virtual public std::basic_ios&lt;CharT, Traits&gt;<br \/>\n{<\/p>\n<p>};<\/p>\n<p>template&lt;class CharT, class Traits &#061; std::char_traits&lt;CharT&gt;&gt;<br \/>\nclass basic_istream : virtual public std::basic_ios&lt;CharT, Traits&gt;<br \/>\n{<\/p>\n<p>}; <\/p>\n<hr \/>\n<h4 id=\"%E5%85%AB%E3%80%81%E7%BB%A7%E6%89%BF%E4%B8%8E%E7%BB%84%E5%90%88\">\u516b\u3001\u7ee7\u627f\u4e0e\u7ec4\u5408<\/h4>\n<ul>\n<li>public\u7ee7\u627f\u662f\u2f00\u79cdis-a\u7684\u5173\u7cfb\u3002\u4e5f\u5c31\u662f\u8bf4\u6bcf\u4e2a\u6d3e\u2f63\u7c7b\u5bf9\u8c61\u90fd\u662f\u2f00\u4e2a\u57fa\u7c7b\u5bf9\u8c61\u3002<\/li>\n<li>\u7ec4\u5408\u662f\u2f00\u79cdhas-a\u7684\u5173\u7cfb\u3002\u5047\u8bbeB\u7ec4\u5408\u4e86A&#xff0c;\u6bcf\u4e2aB\u5bf9\u8c61\u4e2d\u90fd\u6709\u2f00\u4e2aA\u5bf9\u8c61\u3002<\/li>\n<li>\u7ee7\u627f\u5141\u8bb8\u4f60\u6839\u636e\u57fa\u7c7b\u7684\u5b9e\u73b0\u6765\u5b9a\u4e49\u6d3e\u2f63\u7c7b\u7684\u5b9e\u73b0\u3002\u8fd9\u79cd\u901a\u8fc7\u2f63\u6210\u6d3e\u2f63\u7c7b\u7684\u590d\u2f64\u901a\u5e38\u88ab\u79f0\u4e3a\u2f69\u7bb1\u590d\u2f64 (white-box reuse)\u3002\u672f\u8bed\u201c\u2f69\u7bb1\u201d\u662f\u76f8\u5bf9\u53ef\u89c6\u6027\u2f7d\u2f94&#xff1a;\u5728\u7ee7\u627f\u2f45\u5f0f\u4e2d&#xff0c;\u57fa\u7c7b\u7684\u5185\u90e8\u7ec6\u8282\u5bf9\u6d3e\u2f63\u7c7b\u53ef \u2ec5 \u3002\u7ee7\u627f\u2f00\u5b9a\u7a0b\u5ea6\u7834\u574f\u4e86\u57fa\u7c7b\u7684\u5c01\u88c5&#xff0c;\u57fa\u7c7b\u7684\u6539\u53d8&#xff0c;\u5bf9\u6d3e\u2f63\u7c7b\u6709\u5f88\u2f24\u7684\u5f71\u54cd\u3002\u6d3e\u2f63\u7c7b\u548c\u57fa\u7c7b\u95f4\u7684\u4f9d \u8d56\u5173\u7cfb\u5f88\u5f3a&#xff0c;\u8026\u5408\u5ea6\u2fbc\u3002<\/li>\n<li>\u5bf9\u8c61\u7ec4\u5408\u662f\u7c7b\u7ee7\u627f\u4e4b\u5916\u7684\u53e6\u2f00\u79cd\u590d\u2f64\u9009\u62e9\u3002\u65b0\u7684\u66f4\u590d\u6742\u7684\u529f\u80fd\u53ef\u4ee5\u901a\u8fc7\u7ec4\u88c5\u6216\u7ec4\u5408\u5bf9\u8c61\u6765\u83b7\u5f97\u3002\u5bf9 \u8c61\u7ec4\u5408\u8981\u6c42\u88ab\u7ec4\u5408\u7684\u5bf9\u8c61\u5177\u6709\u826f\u597d\u5b9a\u4e49\u7684\u63a5\u2f1d\u3002\u8fd9\u79cd\u590d\u2f64\u2edb\u683c\u88ab\u79f0\u4e3a\u2fca\u7bb1\u590d\u2f64(black-box reuse)&#xff0c; \u56e0\u4e3a\u5bf9\u8c61\u7684\u5185\u90e8\u7ec6\u8282\u662f\u4e0d\u53ef\u2ec5\u7684\u3002\u5bf9\u8c61\u53ea\u4ee5\u201c\u2fca\u7bb1\u201d\u7684\u5f62\u5f0f\u51fa\u73b0\u3002 \u7ec4\u5408\u7c7b\u4e4b\u95f4\u6ca1\u6709\u5f88\u5f3a\u7684\u4f9d\u8d56\u5173 \u7cfb&#xff0c;\u8026\u5408\u5ea6\u4f4e\u3002\u4f18\u5148\u4f7f\u2f64\u5bf9\u8c61\u7ec4\u5408\u6709\u52a9\u4e8e\u4f60\u4fdd\u6301\u6bcf\u4e2a\u7c7b\u88ab\u5c01\u88c5\u3002<\/li>\n<li>\u4f18\u5148\u4f7f\u2f64\u7ec4\u5408&#xff0c;\u2f7d\u4e0d\u662f\u7ee7\u627f\u3002\u5b9e\u9645\u5c3d\u91cf\u591a\u53bb\u2f64\u7ec4\u5408&#xff0c;\u7ec4\u5408\u7684\u8026\u5408\u5ea6\u4f4e&#xff0c;\u4ee3\u7801\u7ef4\u62a4\u6027\u597d\u3002\u4e0d\u8fc7\u4e5f\u4e0d\u592a \u90a3\u4e48\u7edd\u5bf9&#xff0c;\u7c7b\u4e4b\u95f4\u7684\u5173\u7cfb\u5c31\u9002\u5408\u7ee7\u627f(is-a)\u90a3\u5c31\u2f64\u7ee7\u627f&#xff0c;\u53e6\u5916\u8981\u5b9e\u73b0\u591a\u6001&#xff0c;\u4e5f\u5fc5\u987b\u8981\u7ee7\u627f\u3002\u7c7b\u4e4b\u95f4\u7684 \u5173\u7cfb\u65e2\u9002\u5408\u2f64\u7ee7\u627f(is-a)\u4e5f\u9002\u5408\u7ec4\u5408(has-a)&#xff0c;\u5c31\u2f64\u7ec4\u5408<\/li>\n<\/ul>\n<h5 id=\"%E5%9C%BA%E6%99%AF1%EF%BC%9A%E7%BB%A7%E6%89%BF%E7%A4%BA%E4%BE%8B%EF%BC%88is-a%E5%85%B3%E7%B3%BB%EF%BC%89\">\u573a\u666f1&#xff1a;\u7ee7\u627f\u793a\u4f8b&#xff08;is-a\u5173\u7cfb&#xff09;<\/h5>\n<p>\/\/ \u57fa\u7c7b&#xff1a;\u52a8\u7269<br \/>\nclass Animal {<br \/>\nprotected:<br \/>\n    std::string name;<br \/>\npublic:<br \/>\n    Animal(const std::string&amp; n) : name(n) {}<br \/>\n    virtual void eat() const {<br \/>\n        std::cout &lt;&lt; name &lt;&lt; &#034; is eating.&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n    virtual ~Animal() &#061; default; \/\/ \u591a\u6001\u9700\u8981\u865a\u6790\u6784\u51fd\u6570<br \/>\n};<\/p>\n<p>\/\/ \u6d3e\u751f\u7c7b&#xff1a;\u72d7&#xff08;\u7ee7\u627fAnimal&#xff09;<br \/>\nclass Dog : public Animal {<br \/>\npublic:<br \/>\n    Dog(const std::string&amp; n) : Animal(n) {}<br \/>\n    void bark() const {<br \/>\n        std::cout &lt;&lt; name &lt;&lt; &#034; says: Woof!&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n    \/\/ \u91cd\u5199eat\u65b9\u6cd5<br \/>\n    void eat() const override {<br \/>\n        std::cout &lt;&lt; name &lt;&lt; &#034; eats dog food.&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ \u4f7f\u7528<br \/>\nDog myDog(&#034;Buddy&#034;);<br \/>\nmyDog.eat();    \/\/ \u8f93\u51fa: Buddy eats dog food.<br \/>\nmyDog.bark();   \/\/ \u8f93\u51fa: Buddy says: Woof! <\/p>\n<p id=\"\">\u8bbe\u8ba1\u610f\u56fe&#xff1a;<\/p>\n<ul>\n<li>\u7ee7\u627f\u4f53\u73b0&#034;is-a&#034;\u5173\u7cfb&#xff08;\u72d7\u662f\u52a8\u7269&#xff09;<\/li>\n<li>\u901a\u8fc7\u865a\u51fd\u6570\u5b9e\u73b0\u591a\u6001&#xff0c;\u5141\u8bb8\u6d3e\u751f\u7c7b\u5b9a\u5236\u884c\u4e3a<\/li>\n<li>\u57fa\u7c7b\u5c01\u88c5\u901a\u7528\u5c5e\u6027\u548c\u65b9\u6cd5&#xff0c;\u6d3e\u751f\u7c7b\u6269\u5c55\u7279\u5b9a\u529f\u80fd<\/li>\n<\/ul>\n<h5 id=\"%E5%9C%BA%E6%99%AF2%EF%BC%9A%E7%BB%84%E5%90%88%E7%A4%BA%E4%BE%8B%EF%BC%88has-a%E5%85%B3%E7%B3%BB%EF%BC%89\">\u573a\u666f2&#xff1a;\u7ec4\u5408\u793a\u4f8b&#xff08;has-a\u5173\u7cfb&#xff09;<\/h5>\n<p>\/\/ \u7ec4\u4ef6\u7c7b&#xff1a;\u5f15\u64ce<br \/>\nclass Engine {<br \/>\npublic:<br \/>\n    void start() const {<br \/>\n        std::cout &lt;&lt; &#034;Engine started.&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ \u7ec4\u4ef6\u7c7b&#xff1a;\u8f66\u8f6e<br \/>\nclass Wheel {<br \/>\npublic:<br \/>\n    void rotate() const {<br \/>\n        std::cout &lt;&lt; &#034;Wheel rotating.&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ \u7ec4\u5408\u7c7b&#xff1a;\u6c7d\u8f66<br \/>\nclass Car {<br \/>\nprivate:<br \/>\n    Engine engine;  \/\/ \u7ec4\u5408Engine\u5bf9\u8c61<br \/>\n    Wheel wheels[4]; \/\/ \u7ec4\u5408\u591a\u4e2aWheel\u5bf9\u8c61<br \/>\npublic:<br \/>\n    void startCar() {<br \/>\n        engine.start();<br \/>\n        for (auto&amp; wheel : wheels) {<br \/>\n            wheel.rotate();<br \/>\n        }<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ \u4f7f\u7528<br \/>\nCar myCar;<br \/>\nmyCar.startCar();<br \/>\n\/\/ \u8f93\u51fa:<br \/>\n\/\/ Engine started.<br \/>\n\/\/ Wheel rotating. (x4) <\/p>\n<p id=\"\">\u8bbe\u8ba1\u610f\u56fe&#xff1a;<\/p>\n<ul>\n<li>\u7ec4\u5408\u4f53\u73b0&#034;has-a&#034;\u5173\u7cfb&#xff08;\u6c7d\u8f66\u6709\u5f15\u64ce\u548c\u8f66\u8f6e&#xff09;<\/li>\n<li>\u5404\u7ec4\u4ef6\u72ec\u7acb\u5c01\u88c5&#xff0c;\u53ef\u5355\u72ec\u4fee\u6539<\/li>\n<li>\u6c7d\u8f66\u7c7b\u901a\u8fc7\u7ec4\u5408\u4e0d\u540c\u7ec4\u4ef6\u5b9e\u73b0\u529f\u80fd&#xff0c;\u964d\u4f4e\u8026\u5408\u5ea6<\/li>\n<\/ul>\n<h5 id=\"%E5%9C%BA%E6%99%AF3%EF%BC%9A%E7%BB%A7%E6%89%BF%2B%E7%BB%84%E5%90%88%E6%B7%B7%E5%90%88%E4%BD%BF%E7%94%A8\">\u573a\u666f3&#xff1a;\u7ee7\u627f&#043;\u7ec4\u5408\u6df7\u5408\u4f7f\u7528<\/h5>\n<p>\/\/ \u57fa\u7c7b&#xff1a;\u6e38\u620f\u89d2\u8272<br \/>\nclass Character {<br \/>\nprotected:<br \/>\n    int health;<br \/>\npublic:<br \/>\n    Character(int h) : health(h) {}<br \/>\n    virtual void move() const {<br \/>\n        std::cout &lt;&lt; &#034;Character moves.&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ \u6b66\u5668\u7ec4\u4ef6<br \/>\nclass Weapon {<br \/>\npublic:<br \/>\n    virtual void attack() const &#061; 0;<br \/>\n    virtual ~Weapon() &#061; default;<br \/>\n};<\/p>\n<p>class Sword : public Weapon {<br \/>\npublic:<br \/>\n    void attack() const override {<br \/>\n        std::cout &lt;&lt; &#034;Sword slash!&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>class Bow : public Weapon {<br \/>\npublic:<br \/>\n    void attack() const override {<br \/>\n        std::cout &lt;&lt; &#034;Bow shot!&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>\/\/ \u6d3e\u751f\u7c7b&#xff1a;\u6218\u58eb&#xff08;\u7ee7\u627fCharacter&#xff0c;\u7ec4\u5408Weapon&#xff09;<br \/>\nclass Warrior : public Character {<br \/>\nprivate:<br \/>\n    Weapon* weapon;  \/\/ \u7ec4\u5408\u6b66\u5668<br \/>\npublic:<br \/>\n    Warrior(int h, Weapon* w) : Character(h), weapon(w) {}<\/p>\n<p>    void attack() const {<br \/>\n        weapon-&gt;attack();<br \/>\n    }<\/p>\n<p>    void changeWeapon(Weapon* newWeapon) {<br \/>\n        delete weapon;<br \/>\n        weapon &#061; newWeapon;<br \/>\n    }<\/p>\n<p>    ~Warrior() { delete weapon; }<br \/>\n};<\/p>\n<p>\/\/ \u4f7f\u7528<br \/>\nWarrior warrior(100, new Sword());<br \/>\nwarrior.move();     \/\/ \u8f93\u51fa: Character moves.<br \/>\nwarrior.attack();   \/\/ \u8f93\u51fa: Sword slash!<br \/>\nwarrior.changeWeapon(new Bow());<br \/>\nwarrior.attack();   \/\/ \u8f93\u51fa: Bow shot! <\/p>\n<p id=\"\">\u8bbe\u8ba1\u610f\u56fe&#xff1a;<\/p>\n<ul>\n<li>\u7ee7\u627f\u5efa\u7acb\u89d2\u8272\u7c7b\u578b\u4f53\u7cfb&#xff08;Warrior\u662fCharacter&#xff09;<\/li>\n<li>\u7ec4\u5408\u5b9e\u73b0\u6b66\u5668\u7cfb\u7edf\u7684\u7075\u6d3b\u6269\u5c55<\/li>\n<li>\u901a\u8fc7\u591a\u6001\u6b66\u5668\u63a5\u53e3\u652f\u6301\u4e0d\u540c\u6b66\u5668\u7c7b\u578b<\/li>\n<li>\u89d2\u8272\u4e0e\u6b66\u5668\u89e3\u8026&#xff0c;\u53ef\u72ec\u7acb\u53d8\u5316<\/li>\n<\/ul>\n<h5 id=\"%E7%BB%A7%E6%89%BF%20vs%20%E7%BB%84%E5%90%88%E7%9A%84%E9%80%89%E6%8B%A9%E5%8E%9F%E5%88%99\">\u7ee7\u627f vs \u7ec4\u5408\u7684\u9009\u62e9\u539f\u5219<\/h5>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"326\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201810-68892c820e536.png\" width=\"500\" \/><\/p>\n<p id=\"\">\u5178\u578b\u5e94\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u4f18\u5148\u4f7f\u7528\u7ec4\u5408&#xff1a;GUI\u7ec4\u4ef6\u3001\u63d2\u4ef6\u7cfb\u7edf\u3001\u7b56\u7565\u6a21\u5f0f<\/li>\n<li>\u5408\u7406\u4f7f\u7528\u7ee7\u627f&#xff1a;UI\u63a7\u4ef6\u5c42\u6b21\u7ed3\u6784\u3001\u56fe\u5f62\u7cfb\u7edf&#xff08;\u5706\u5f62\/\u77e9\u5f62\u7ee7\u627f\u81ea\u5f62\u72b6&#xff09;<\/li>\n<li>\u6df7\u5408\u4f7f\u7528&#xff1a;\u6e38\u620f\u5b9e\u4f53\u7cfb\u7edf&#xff08;\u89d2\u8272\u7ee7\u627f\u57fa\u7840\u5c5e\u6027&#xff0c;\u7ec4\u5408\u88c5\u5907\u7cfb\u7edf&#xff09;<\/li>\n<\/ul>\n<h5 id=\"%E5%86%8D%E4%B8%BE%E4%B8%80%E4%BE%8B\">\u518d\u4e3e\u4e00\u4f8b<\/h5>\n<p>\/\/ Tire(\u8f6e\u80ce)\u548cCar(\u2ecb)\u66f4\u7b26\u5408has-a\u7684\u5173\u7cfb<br \/>\nclass Tire {<br \/>\nprotected:<br \/>\nstring _brand &#061; &#034;Michelin&#034;; \/\/ \u54c1\u724c<br \/>\nsize_t _size &#061; 17; \/\/ \u5c3a\u2f28<br \/>\n};<br \/>\nclass Car {<br \/>\nprotected:<br \/>\nstring _colour &#061; &#034;\u2f69\u2f8a&#034;; \/\/ \u989c\u2f8a<br \/>\nstring _num &#061; &#034;\u9655ABIT00&#034;; \/\/ \u2ecb\u724c\u53f7<br \/>\nTire _t1; \/\/ \u8f6e\u80ce<br \/>\nTire _t2; \/\/ \u8f6e\u80ce<br \/>\nTire _t3; \/\/ \u8f6e\u80ce<br \/>\nTire _t4; \/\/ \u8f6e\u80ce<br \/>\n};<br \/>\nclass BMW : public Car {<\/p>\n<p>public:<br \/>\nvoid Drive() { cout &lt;&lt; &#034;\u597d\u5f00-\u64cd\u63a7&#034; &lt;&lt; endl; }<br \/>\n};<br \/>\n\/\/ Car\u548cBMW\/Benz\u66f4\u7b26\u5408is-a\u7684\u5173\u7cfb<br \/>\nclass Benz : public Car {<br \/>\npublic:<br \/>\nvoid Drive() { cout &lt;&lt; &#034;\u597d\u5750-\u8212\u9002&#034; &lt;&lt; endl; }<br \/>\n};<br \/>\ntemplate&lt;class T&gt;<br \/>\nclass vector<br \/>\n{<br \/>\n};<br \/>\n\/\/ stack\u548cvector\u7684\u5173\u7cfb&#xff0c;\u65e2\u7b26\u5408is-a&#xff0c;\u4e5f\u7b26\u5408has-a<br \/>\ntemplate&lt;class T&gt;<br \/>\nclass stack : public vector&lt;T&gt;<br \/>\n{<br \/>\n};<br \/>\ntemplate&lt;class T&gt;<br \/>\nclass stack<br \/>\n{<br \/>\npublic:<br \/>\nvector&lt;T&gt; _v;<br \/>\n};<br \/>\nint main()<br \/>\n{<br \/>\nreturn 0;<br \/>\n} <\/p>\n<p>\u5b8c\u2014\u2014<\/p>\n<hr \/>\n<p>\u661f\u5149\u4e0b\u7684\u68a6\u60f3_\u6a58\u732b\u70e7\u9cb7\u9c7c<\/p>\n<p style=\"text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" class=\"right\" height=\"300\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201810-68892c823972e.jpg\" width=\"300\" \/><\/p>\n<p>\u81f3\u6b64\u7ed3\u675f\u2014\u2014<\/p>\n<p>\u6211\u662f<span style=\"color:#ff9900\">\u4e91\u8fb9\u6709\u4e2a\u7a3b\u8349\u4eba<\/span><\/p>\n<p>\u671f\u5f85\u4e0e\u4f60\u7684\u4e0b\u4e00\u6b21\u76f8\u9047&#8230;&#8230;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3w\u6b21\uff0c\u70b9\u8d5e122\u6b21\uff0c\u6536\u85cf111\u6b21\u3002\u6458\u8981\uff1a\u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86C++\u7ee7\u627f\u673a\u5236\u53ca\u5176\u76f8\u5173\u7279\u6027\uff0c\u5305\u62ec\u7ee7\u627f\u6982\u5ff5\u3001\u5b9a\u4e49\u683c\u5f0f\u3001\u8bbf\u95ee\u65b9\u5f0f\u53d8\u5316\u3001\u57fa\u7c7b\u6d3e\u751f\u7c7b\u8f6c\u6362\u3001\u4f5c\u7528\u57df\u89c4\u5219\u3001\u6d3e\u751f\u7c7b\u6210\u5458\u51fd\u6570\u5b9e\u73b0\u7b49\u6838\u5fc3\u5185\u5bb9\u3002\u91cd\u70b9\u5206\u6790\u4e86\u591a\u7ee7\u627f\u5e26\u6765\u7684\u83f1\u5f62\u7ee7\u627f\u95ee\u9898\u53ca\u865a\u7ee7\u627f\u89e3\u51b3\u65b9\u6848\uff0c\u5e76\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u5bf9\u6bd4\u4e86\u7ee7\u627f\u4e0e\u7ec4\u5408\u7684\u8bbe\u8ba1\u5dee\u5f02\u3002\u6587\u7ae0\u8fd8\u63a2\u8ba8\u4e86\u7ee7\u627f\u4e0e\u53cb\u5143\u3001\u9759\u6001\u6210\u5458\u7684\u5173\u7cfb\uff0c\u4ee5\u53ca\u5982\u4f55\u5b9e\u73b0\u4e0d\u53ef\u7ee7\u627f\u7684\u7c7b\u7b49\u5b9e\u7528\u6280\u5de7\u3002\u6700\u540e\u603b\u7ed3\u4e86\u7ee7\u627f\u4e0e\u7ec4\u5408\u7684\u9009\u62e9\u539f\u5219\uff0c\u5f3a\u8c03\u5e94\u6839\u636e\u5b9e\u9645\u9700\u6c42\u5408\u7406\u4f7f\u7528\u8fd9\u4e24\u79cd\u4ee3\u7801\u590d\u7528\u65b9\u5f0f\u3002\u5168\u6587\u5185\u5bb9\u7cfb\u7edf\u5168\u9762\uff0c\u9002\u5408C++\u5f00\u53d1\u8005\u6df1\u5165\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u7684\u7ee7\u627f\u673a\u5236\u3002<\/p>\n","protected":false},"author":2,"featured_media":46823,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,4464,4463,4465,4467,4466,4468],"topic":[],"class_list":["post-46837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-4464","tag-4463","tag-4465","tag-4467","tag-4466","tag-4468"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/46837.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3w\u6b21\uff0c\u70b9\u8d5e122\u6b21\uff0c\u6536\u85cf111\u6b21\u3002\u6458\u8981\uff1a\u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86C++\u7ee7\u627f\u673a\u5236\u53ca\u5176\u76f8\u5173\u7279\u6027\uff0c\u5305\u62ec\u7ee7\u627f\u6982\u5ff5\u3001\u5b9a\u4e49\u683c\u5f0f\u3001\u8bbf\u95ee\u65b9\u5f0f\u53d8\u5316\u3001\u57fa\u7c7b\u6d3e\u751f\u7c7b\u8f6c\u6362\u3001\u4f5c\u7528\u57df\u89c4\u5219\u3001\u6d3e\u751f\u7c7b\u6210\u5458\u51fd\u6570\u5b9e\u73b0\u7b49\u6838\u5fc3\u5185\u5bb9\u3002\u91cd\u70b9\u5206\u6790\u4e86\u591a\u7ee7\u627f\u5e26\u6765\u7684\u83f1\u5f62\u7ee7\u627f\u95ee\u9898\u53ca\u865a\u7ee7\u627f\u89e3\u51b3\u65b9\u6848\uff0c\u5e76\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u5bf9\u6bd4\u4e86\u7ee7\u627f\u4e0e\u7ec4\u5408\u7684\u8bbe\u8ba1\u5dee\u5f02\u3002\u6587\u7ae0\u8fd8\u63a2\u8ba8\u4e86\u7ee7\u627f\u4e0e\u53cb\u5143\u3001\u9759\u6001\u6210\u5458\u7684\u5173\u7cfb\uff0c\u4ee5\u53ca\u5982\u4f55\u5b9e\u73b0\u4e0d\u53ef\u7ee7\u627f\u7684\u7c7b\u7b49\u5b9e\u7528\u6280\u5de7\u3002\u6700\u540e\u603b\u7ed3\u4e86\u7ee7\u627f\u4e0e\u7ec4\u5408\u7684\u9009\u62e9\u539f\u5219\uff0c\u5f3a\u8c03\u5e94\u6839\u636e\u5b9e\u9645\u9700\u6c42\u5408\u7406\u4f7f\u7528\u8fd9\u4e24\u79cd\u4ee3\u7801\u590d\u7528\u65b9\u5f0f\u3002\u5168\u6587\u5185\u5bb9\u7cfb\u7edf\u5168\u9762\uff0c\u9002\u5408C++\u5f00\u53d1\u8005\u6df1\u5165\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u7684\u7ee7\u627f\u673a\u5236\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46837.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T20:18:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201750-68892c6ece72c.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46837.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46837.html\",\"name\":\"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T20:18:11+00:00\",\"dateModified\":\"2025-07-29T20:18:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46837.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46837.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46837.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/46837.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3w\u6b21\uff0c\u70b9\u8d5e122\u6b21\uff0c\u6536\u85cf111\u6b21\u3002\u6458\u8981\uff1a\u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86C++\u7ee7\u627f\u673a\u5236\u53ca\u5176\u76f8\u5173\u7279\u6027\uff0c\u5305\u62ec\u7ee7\u627f\u6982\u5ff5\u3001\u5b9a\u4e49\u683c\u5f0f\u3001\u8bbf\u95ee\u65b9\u5f0f\u53d8\u5316\u3001\u57fa\u7c7b\u6d3e\u751f\u7c7b\u8f6c\u6362\u3001\u4f5c\u7528\u57df\u89c4\u5219\u3001\u6d3e\u751f\u7c7b\u6210\u5458\u51fd\u6570\u5b9e\u73b0\u7b49\u6838\u5fc3\u5185\u5bb9\u3002\u91cd\u70b9\u5206\u6790\u4e86\u591a\u7ee7\u627f\u5e26\u6765\u7684\u83f1\u5f62\u7ee7\u627f\u95ee\u9898\u53ca\u865a\u7ee7\u627f\u89e3\u51b3\u65b9\u6848\uff0c\u5e76\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u5bf9\u6bd4\u4e86\u7ee7\u627f\u4e0e\u7ec4\u5408\u7684\u8bbe\u8ba1\u5dee\u5f02\u3002\u6587\u7ae0\u8fd8\u63a2\u8ba8\u4e86\u7ee7\u627f\u4e0e\u53cb\u5143\u3001\u9759\u6001\u6210\u5458\u7684\u5173\u7cfb\uff0c\u4ee5\u53ca\u5982\u4f55\u5b9e\u73b0\u4e0d\u53ef\u7ee7\u627f\u7684\u7c7b\u7b49\u5b9e\u7528\u6280\u5de7\u3002\u6700\u540e\u603b\u7ed3\u4e86\u7ee7\u627f\u4e0e\u7ec4\u5408\u7684\u9009\u62e9\u539f\u5219\uff0c\u5f3a\u8c03\u5e94\u6839\u636e\u5b9e\u9645\u9700\u6c42\u5408\u7406\u4f7f\u7528\u8fd9\u4e24\u79cd\u4ee3\u7801\u590d\u7528\u65b9\u5f0f\u3002\u5168\u6587\u5185\u5bb9\u7cfb\u7edf\u5168\u9762\uff0c\u9002\u5408C++\u5f00\u53d1\u8005\u6df1\u5165\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u7684\u7ee7\u627f\u673a\u5236\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/46837.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T20:18:11+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729201750-68892c6ece72c.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"11 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46837.html","url":"https:\/\/www.wsisp.com\/helps\/46837.html","name":"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T20:18:11+00:00","dateModified":"2025-07-29T20:18:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46837.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46837.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46837.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++\u3011\u7b2c\u5341\u4e94\u8282\u2014\u4e00\u6587\u8be6\u89e3 | \u7ee7\u627f"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=46837"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46837\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/46823"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46837"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}