{"id":108963,"date":"2026-09-23T03:08:53","date_gmt":"2026-09-22T19:08:53","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/108963.html"},"modified":"2026-09-23T03:08:53","modified_gmt":"2026-09-22T19:08:53","slug":"%e3%80%90c%e8%bf%9b%e9%98%b6%e3%80%91%e7%bb%a7%e6%89%bf","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/108963.html","title":{"rendered":"\u3010C++\u8fdb\u9636\u3011\u7ee7\u627f"},"content":{"rendered":"<h3 id=\"%E2%80%8B%E7%BC%96%E8%BE%91\">\u00a0\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"624\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190849-6ab2d241dabe4.jpg\" width=\"2048\" \/><\/h3>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E2%80%8B%E7%BC%96%E8%BE%91-toc\" style=\"margin-left:40px\">\u00a0\u00a0\u200b\u7f16\u8f91<\/p>\n<p id=\"%E6%9C%AC%E8%8A%82%E5%AD%A6%E4%B9%A0%E7%9B%AE%E6%A0%87-toc\" style=\"margin-left:40px\">\u672c\u8282\u5b66\u4e60\u76ee\u6807<\/p>\n<p id=\"1.%20%E7%BB%A7%E6%89%BF%E7%9A%84%E6%A6%82%E5%BF%B5%E5%8F%8A%E5%AE%9A%E4%B9%89-toc\" style=\"margin-left:40px\">1. \u7ee7\u627f\u7684\u6982\u5ff5\u53ca\u5b9a\u4e49<\/p>\n<p id=\"1.1%20%E4%BB%80%E4%B9%88%E6%98%AF%E7%BB%A7%E6%89%BF-toc\" style=\"margin-left:80px\">1.1 \u4ec0\u4e48\u662f\u7ee7\u627f<\/p>\n<p id=\"1.2%20%E7%BB%A7%E6%89%BF%E5%AE%9A%E4%B9%89%E8%AF%AD%E6%B3%95-toc\" style=\"margin-left:80px\">1.2 \u7ee7\u627f\u5b9a\u4e49\u8bed\u6cd5<\/p>\n<p id=\"%E5%9F%BA%E7%B1%BB%E6%88%90%E5%91%98%E5%9C%A8%E6%B4%BE%E7%94%9F%E7%B1%BB%E7%9A%84%E8%AE%BF%E9%97%AE%E8%A7%84%E5%88%99-toc\" style=\"margin-left:120px\">\u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u7684\u8bbf\u95ee\u89c4\u5219<\/p>\n<p id=\"1.3%20%E7%BB%A7%E6%89%BF%E6%A8%A1%E6%9D%BF%E7%B1%BB%EF%BC%88%E6%A8%A1%E6%9D%BF%E7%88%B6%E7%B1%BB%EF%BC%89-toc\" style=\"margin-left:80px\">1.3 \u7ee7\u627f\u6a21\u677f\u7c7b&#xff08;\u6a21\u677f\u7236\u7c7b&#xff09;<\/p>\n<p id=\"2.%20%E5%9F%BA%E7%B1%BB%E4%B8%8E%E6%B4%BE%E7%94%9F%E7%B1%BB%E5%AF%B9%E8%B1%A1%E8%BD%AC%E6%8D%A2%EF%BC%88%E5%88%87%E7%89%87%20%2F%20%E5%88%87%E5%89%B2%20slicing%EF%BC%89-toc\" style=\"margin-left:40px\">2. \u57fa\u7c7b\u4e0e\u6d3e\u751f\u7c7b\u5bf9\u8c61\u8f6c\u6362&#xff08;\u5207\u7247 \/ \u5207\u5272 slicing&#xff09;<\/p>\n<p id=\"3.%20%E7%BB%A7%E6%89%BF%E4%BD%93%E7%B3%BB%E4%B8%8B%E4%BD%9C%E7%94%A8%E5%9F%9F%E4%B8%8E%E9%9A%90%E8%97%8F%EF%BC%88name%E2%80%91hiding%EF%BC%89-toc\" style=\"margin-left:40px\">3. \u7ee7\u627f\u4f53\u7cfb\u4e0b\u4f5c\u7528\u57df\u4e0e\u9690\u85cf&#xff08;name\u2011hiding&#xff09;<\/p>\n<p id=\"%E5%90%8C%E5%90%8D%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E9%9A%90%E8%97%8F%E7%A4%BA%E4%BE%8B-toc\" style=\"margin-left:80px\">\u540c\u540d\u6210\u5458\u53d8\u91cf\u9690\u85cf\u793a\u4f8b<\/p>\n<p id=\"%E5%90%8C%E5%90%8D%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0%E9%9A%90%E8%97%8F%EF%BC%88%E9%87%8D%E7%82%B9%E9%80%89%E6%8B%A9%E9%A2%98%EF%BC%89-toc\" style=\"margin-left:80px\">\u540c\u540d\u6210\u5458\u51fd\u6570\u9690\u85cf&#xff08;\u91cd\u70b9\u9009\u62e9\u9898&#xff09;<\/p>\n<p id=\"4.%20%E6%B4%BE%E7%94%9F%E7%B1%BB%E7%9A%84%E9%BB%98%E8%AE%A4%206%20%E4%B8%AA%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:40px\">4. \u6d3e\u751f\u7c7b\u7684\u9ed8\u8ba4 6 \u4e2a\u6210\u5458\u51fd\u6570<\/p>\n<p id=\"%E6%B4%BE%E7%94%9F%E7%B1%BB%E9%BB%98%E8%AE%A4%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0%E6%89%A7%E8%A1%8C%E8%A7%84%E5%88%99-toc\" style=\"margin-left:80px\">\u6d3e\u751f\u7c7b\u9ed8\u8ba4\u6210\u5458\u51fd\u6570\u6267\u884c\u89c4\u5219<\/p>\n<p id=\"4.2%20%E7%A6%81%E6%AD%A2%E7%B1%BB%E8%A2%AB%E7%BB%A7%E6%89%BF%E4%B8%A4%E7%A7%8D%E5%86%99%E6%B3%95-toc\" style=\"margin-left:80px\">4.2 \u7981\u6b62\u7c7b\u88ab\u7ee7\u627f\u4e24\u79cd\u5199\u6cd5<\/p>\n<p id=\"5.%20%E7%BB%A7%E6%89%BF%E4%B8%8E%E5%8F%8B%E5%85%83-toc\" style=\"margin-left:40px\">5. \u7ee7\u627f\u4e0e\u53cb\u5143<\/p>\n<p id=\"6.%20%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:40px\">6. \u7ee7\u627f\u4e0e\u9759\u6001\u6210\u5458<\/p>\n<p id=\"7.%20%E5%A4%9A%E7%BB%A7%E6%89%BF%E3%80%81%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF%E4%B8%8E%E8%99%9A%E7%BB%A7%E6%89%BF%20virtual-toc\" style=\"margin-left:40px\">7. \u591a\u7ee7\u627f\u3001\u83f1\u5f62\u7ee7\u627f\u4e0e\u865a\u7ee7\u627f virtual<\/p>\n<p id=\"7.1%20%E5%8D%95%E7%BB%A7%E6%89%BF%E3%80%81%E5%A4%9A%E7%BB%A7%E6%89%BF-toc\" style=\"margin-left:80px\">7.1 \u5355\u7ee7\u627f\u3001\u591a\u7ee7\u627f<\/p>\n<p id=\"7.2%20%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF%EF%BC%88%E9%92%BB%E7%9F%B3%E7%BB%A7%E6%89%BF%EF%BC%89%E2%80%94%E2%80%94%20%E5%A4%9A%E7%BB%A7%E6%89%BF%E7%89%B9%E6%AE%8A%E5%9D%91-toc\" style=\"margin-left:80px\">7.2 \u83f1\u5f62\u7ee7\u627f&#xff08;\u94bb\u77f3\u7ee7\u627f&#xff09;\u2014\u2014 \u591a\u7ee7\u627f\u7279\u6b8a\u5751<\/p>\n<p id=\"7.3%20%E8%99%9A%E7%BB%A7%E6%89%BF%20virtual%20%E8%A7%A3%E5%86%B3%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF-toc\" style=\"margin-left:80px\">7.3 \u865a\u7ee7\u627f virtual \u89e3\u51b3\u83f1\u5f62\u7ee7\u627f<\/p>\n<p id=\"8.%20%E7%BB%A7%E6%89%BF%E4%B8%8E%E7%BB%84%E5%90%88-toc\" style=\"margin-left:40px\">8. \u7ee7\u627f\u4e0e\u7ec4\u5408<\/p>\n<p id=\"8.1%20is%E2%80%91a%20vs%20has%E2%80%91a-toc\" style=\"margin-left:80px\">8.1 is\u2011a vs has\u2011a<\/p>\n<p id=\"%F0%9F%93%94%E6%9C%AC%E7%AF%87%E6%A0%B8%E5%BF%83%E8%80%83%E7%82%B9%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:40px\">&#x1f4d4;\u672c\u7bc7\u6838\u5fc3\u8003\u70b9\u603b\u7ed3<\/p>\n<\/p>\n<h3 id=\"%E6%9C%AC%E8%8A%82%E5%AD%A6%E4%B9%A0%E7%9B%AE%E6%A0%87\">\u672c\u8282\u5b66\u4e60\u76ee\u6807<\/h3>\n<li>\u7406\u89e3\u7ee7\u627f\u7684\u6982\u5ff5&#xff0c;\u89e3\u51b3\u4ee3\u7801\u5197\u4f59\u590d\u7528\u95ee\u9898&#xff0c;\u5206\u6e05\u7236\u7c7b (\u57fa\u7c7b)\/ \u5b50\u7c7b (\u6d3e\u751f\u7c7b)<\/li>\n<li>\u638c\u63e1\u4e09\u79cd\u7ee7\u627f\u65b9\u5f0fpublic \/ protected \/ private&#xff0c;\u638c\u63e1\u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u4e2d\u7684\u8bbf\u95ee\u89c4\u5219<\/li>\n<li>\u7406\u89e3\u6d3e\u751f\u7c7b\u5bf9\u8c61\u5207\u7247&#xff0c;\u57fa\u7c7b\u6d3e\u751f\u7c7b\u6307\u9488\u5f15\u7528\u8f6c\u6362<\/li>\n<li>\u7ee7\u627f\u4f53\u7cfb\u4f5c\u7528\u57df\u3001\u6210\u5458\u9690\u85cf&#xff08;name\u2011hiding&#xff09;&#xff0c;\u533a\u5206\u9690\u85cf\u548c\u91cd\u8f7d<\/li>\n<li>\u6d3e\u751f\u7c7b 6 \u4e2a\u9ed8\u8ba4\u6210\u5458\u51fd\u6570&#xff1a;\u6784\u9020\u3001\u62f7\u8d1d\u6784\u9020\u3001\u8d4b\u503c\u91cd\u8f7d\u3001\u6790\u6784\u7684\u6267\u884c\u89c4\u5219<\/li>\n<li>final \u7981\u6b62\u7ee7\u627f&#xff0c;\u7ee7\u627f\u4e0e\u53cb\u5143\u3001\u7ee7\u627f\u4e0e\u9759\u6001\u6210\u5458<\/li>\n<li>\u7406\u89e3\u591a\u7ee7\u627f\u3001\u83f1\u5f62\u7ee7\u627f\u5e26\u6765\u4e8c\u4e49\u6027\u4e0e\u6570\u636e\u5197\u4f59&#xff0c;\u638c\u63e1\u865a\u7ee7\u627fvirtual\u89e3\u51b3\u83f1\u5f62\u95ee\u9898<\/li>\n<li>\u5206\u6e05is\u2011a\u7ee7\u627f \u548chas\u2011a\u7ec4\u5408&#xff0c;\u7406\u89e3\u767d\u7bb1\u590d\u7528\u3001\u9ed1\u7bb1\u590d\u7528&#xff0c;\u5f00\u53d1\u4f18\u5148\u7ec4\u5408<\/li>\n<h3 id=\"1.%20%E7%BB%A7%E6%89%BF%E7%9A%84%E6%A6%82%E5%BF%B5%E5%8F%8A%E5%AE%9A%E4%B9%89\">1. \u7ee7\u627f\u7684\u6982\u5ff5\u53ca\u5b9a\u4e49<\/h3>\n<h4 id=\"1.1%20%E4%BB%80%E4%B9%88%E6%98%AF%E7%BB%A7%E6%89%BF\">1.1 \u4ec0\u4e48\u662f\u7ee7\u627f<\/h4>\n<p>\u7ee7\u627f\u662f\u9762\u5411\u5bf9\u8c61\u5b9e\u73b0\u4ee3\u7801\u590d\u7528\u6700\u91cd\u8981\u673a\u5236\u3002 \u5728\u4fdd\u7559\u539f\u6709\u7c7b&#xff08;\u57fa\u7c7b \/ \u7236\u7c7b&#xff09;\u5168\u90e8\u7279\u6027\u7684\u57fa\u7840\u4e4b\u4e0a&#xff0c;\u6269\u5c55\u51fa\u65b0\u7684\u7c7b&#xff08;\u6d3e\u751f\u7c7b \/ \u5b50\u7c7b&#xff09;\u3002<\/p>\n<p>\u573a\u666f&#xff1a;\u5b66\u751f Student\u3001\u8001\u5e08 Teacher\u3002\u4e24\u8005\u90fd\u5305\u542b\u59d3\u540d\u3001\u5730\u5740\u3001\u7535\u8bdd\u3001\u5e74\u9f84\u3001\u8eab\u4efd\u8ba4\u8bc1identity()&#xff1b;\u5b66\u751f\u72ec\u6709\u5b66\u53f7\u3001\u5b66\u4e60&#xff1b;\u8001\u5e08\u72ec\u6709\u804c\u79f0\u3001\u6388\u8bfe\u3002 \u4e0d\u4f7f\u7528\u7ee7\u627f&#xff0c;\u4e24\u4efd\u7c7b\u4e2d\u91cd\u590d\u5199\u76f8\u540c\u6210\u5458&#xff0c;\u4ee3\u7801\u5927\u91cf\u5197\u4f59\u3002<\/p>\n<p>\u628a\u516c\u5171\u5c5e\u6027\u3001\u65b9\u6cd5\u62bd\u51fa\u6765\u653e\u5230Person\u7236\u7c7b&#xff1b;Student\u3001Teacher\u7ee7\u627f Person&#xff0c;\u76f4\u63a5\u590d\u7528\u7236\u7c7b\u6210\u5458&#xff0c;\u53ea\u5199\u81ea\u5df1\u72ec\u6709\u7684\u5185\u5bb9\u3002<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>\/\/\u7236\u7c7b&#xff08;\u57fa\u7c7b&#xff09;<br \/>\nclass Person<br \/>\n{<br \/>\npublic:<br \/>\n    void identity()<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;void identity() &#034; &lt;&lt; _name &lt;&lt; endl;<br \/>\n    }<br \/>\nprotected:<br \/>\n    string _name &#061; &#034;\u5f20\u4e09&#034;;<br \/>\n    string _address;<br \/>\n    string _tel;<br \/>\n    int _age &#061; 18;<br \/>\n};<\/p>\n<p>\/\/\u5b50\u7c7b&#xff08;\u6d3e\u751f\u7c7b&#xff09; public\u7ee7\u627fPerson<br \/>\nclass Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\n    void study()<br \/>\n    { }<br \/>\nprotected:<br \/>\n    int _stuid; \/\/\u5b66\u53f7<br \/>\n};<\/p>\n<p>class Teacher : public Person<br \/>\n{<br \/>\npublic:<br \/>\n    void teaching()<br \/>\n    { }<br \/>\nprotected:<br \/>\n    string _title; \/\/\u804c\u79f0<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Student s;<br \/>\n    Teacher t;<br \/>\n    s.identity(); \/\/\u590d\u7528\u7236\u7c7b\u65b9\u6cd5<br \/>\n    t.identity();<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4 id=\"1.2%20%E7%BB%A7%E6%89%BF%E5%AE%9A%E4%B9%89%E8%AF%AD%E6%B3%95\">1.2 \u7ee7\u627f\u5b9a\u4e49\u8bed\u6cd5<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"184\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190850-6ab2d242e506d.png\" width=\"288\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"185\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d2430ce01.png\" width=\"325\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"182\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d2432569d.png\" width=\"322\" \/><\/p>\n<p>class \u6d3e\u751f\u7c7b\u540d : \u7ee7\u627f\u65b9\u5f0f \u57fa\u7c7b\u540d<br \/>\n{<br \/>\n    \/\/\u6d3e\u751f\u7c7b\u81ea\u5df1\u65b0\u589e\u7684\u6210\u5458<br \/>\n};<\/p>\n<p>\u7ee7\u627f\u4e09\u79cd\u65b9\u5f0f&#xff1a;public\u3001protected\u3001private<\/p>\n<h5 id=\"%E5%9F%BA%E7%B1%BB%E6%88%90%E5%91%98%E5%9C%A8%E6%B4%BE%E7%94%9F%E7%B1%BB%E7%9A%84%E8%AE%BF%E9%97%AE%E8%A7%84%E5%88%99\">\u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u7684\u8bbf\u95ee\u89c4\u5219<\/h5>\n<li>\u57fa\u7c7b\u7684 private \u79c1\u6709\u6210\u5458&#xff1a;\u65e0\u8bba\u54ea\u79cd\u7ee7\u627f\u65b9\u5f0f&#xff0c;\u5728\u6d3e\u751f\u7c7b\u5185\u90e8\u90fd\u4e0d\u53ef\u89c1\u3002<\/li>\n<p>\u6ce8\u610f&#xff1a;\u4e0d\u662f\u6ca1\u6709\u7ee7\u627f\u5230\u5b50\u7c7b\u5bf9\u8c61\u4e2d&#xff0c;\u53ea\u662f\u8bed\u6cd5\u7981\u6b62\u8bbf\u95ee&#xff0c;\u5bf9\u8c61\u5185\u5b58\u91cc\u9762\u4f9d\u7136\u5b58\u5728\u8fd9\u4efd\u6570\u636e\u3002 \u5982\u679c\u5e0c\u671b\u5b50\u7c7b\u53ef\u4ee5\u8bbf\u95ee&#xff0c;\u4f46\u662f\u5916\u90e8\u4e0d\u80fd\u8bbf\u95ee&#xff0c;\u6210\u5458\u8bbe\u7f6e\u4e3aprotected&#xff0c;protected \u5c31\u662f\u4e3a\u7ee7\u627f\u573a\u666f\u8bde\u751f\u3002<\/p>\n<li><span style=\"background-color:#ffd900\">\u7b80\u5355\u53e3\u8bc0&#xff1a;<\/span><span style=\"background-color:#ffd900\">\u6d3e\u751f\u7c7b\u4e2d\u8bbf\u95ee\u6743\u9650 &#061; min(\u57fa\u7c7b\u6210\u5458\u6743\u9650&#xff0c;\u7ee7\u627f\u65b9\u5f0f)<\/span><span style=\"background-color:#ffd900\"> \u6743\u9650\u4f18\u5148\u7ea7&#xff1a;<\/span><span style=\"background-color:#ffd900\">public &gt; protected &gt; private<\/span><\/li>\n<p>\u8868\u683c<\/p>\n<table>\n<tr>\u57fa\u7c7b\u6210\u5458public \u7ee7\u627fprotected \u7ee7\u627fprivate \u7ee7\u627f<\/tr>\n<tbody>\n<tr>\n<td>public<\/td>\n<td>public<\/td>\n<td>protected<\/td>\n<td>private<\/td>\n<\/tr>\n<tr>\n<td>protected<\/td>\n<td>protected<\/td>\n<td>protected<\/td>\n<td>private<\/td>\n<\/tr>\n<tr>\n<td>private<\/td>\n<td>\u4e0d\u53ef\u89c1<\/td>\n<td>\u4e0d\u53ef\u89c1<\/td>\n<td>\u4e0d\u53ef\u89c1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<li>\u8bed\u6cd5\u7ec6\u8282&#xff1a;<\/li>\n<ul>\n<li>\u4f7f\u7528class\u5b9a\u4e49\u7c7b&#xff0c;\u9ed8\u8ba4\u7ee7\u627f\u65b9\u5f0f\u662f private&#xff1b;<\/li>\n<li>\u4f7f\u7528struct\u5b9a\u4e49\u7c7b&#xff0c;\u9ed8\u8ba4\u7ee7\u627f\u65b9\u5f0f\u662f public&#xff1b;<\/li>\n<li>\u2705\u5de5\u7a0b\u5f00\u53d1\u7edd\u5927\u591a\u6570\u573a\u666f\u53ea\u7528public\u7ee7\u627f&#xff1b;protected\/private\u7ee7\u627f\u6781\u5c11\u4f7f\u7528&#xff0c;\u6269\u5c55\u6027\u5dee\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b\u6f14\u793a\u4e09\u79cd\u7ee7\u627f&#xff1a;<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\n    void Print() { cout &lt;&lt; _name &lt;&lt; endl; }<br \/>\nprotected:<br \/>\n    string _name;<br \/>\nprivate:<br \/>\n    int _age;<br \/>\n};<\/p>\n<p>\/\/ class Student : protected Person;<br \/>\n\/\/ class Student : private Person;<br \/>\nclass Student : public Person<br \/>\n{<br \/>\nprotected:<br \/>\n    int _stunum;<br \/>\n};<\/p>\n<h4 id=\"1.3%20%E7%BB%A7%E6%89%BF%E6%A8%A1%E6%9D%BF%E7%B1%BB%EF%BC%88%E6%A8%A1%E6%9D%BF%E7%88%B6%E7%B1%BB%EF%BC%89\">1.3 \u7ee7\u627f\u6a21\u677f\u7c7b&#xff08;\u6a21\u677f\u7236\u7c7b&#xff09;<\/h4>\n<p>\u5982\u679c\u7236\u7c7b\u662f\u7c7b\u6a21\u677f&#xff0c;\u5b50\u7c7b\u7ee7\u627f\u7684\u65f6\u5019&#xff0c;\u5fc5\u987b\u5e26\u4e0a\u57fa\u7c7b\u6a21\u677f\u57df&#xff0c;\u5426\u5219\u7f16\u8bd1\u5668\u627e\u4e0d\u5230\u57fa\u7c7b\u6210\u5458\u3002 \u4f8b&#xff1a;stack \u7ee7\u627f vector&#xff0c;\u6a21\u62df\u6808\u3002<\/p>\n<p>namespace bit<br \/>\n{<br \/>\ntemplate&lt;class T&gt;<br \/>\nclass stack : public std::vector&lt;T&gt;<br \/>\n{<br \/>\npublic:<br \/>\n    void push(const T&amp; x)<br \/>\n    {<br \/>\n        \/\/ \u5fc5\u987b\u5199 vector&lt;T&gt;::push_back(x);<br \/>\n        \/\/ push_back(x); \/\/\u76f4\u63a5\u5199\u4f1a\u7f16\u8bd1\u62a5\u9519&#xff0c;\u6a21\u677f\u6309\u9700\u5b9e\u4f8b\u5316\u627e\u4e0d\u5230\u540d\u5b57<br \/>\n        vector&lt;T&gt;::push_back(x);<br \/>\n    }<br \/>\n    void pop()<br \/>\n    {<br \/>\n        vector&lt;T&gt;::pop_back();<br \/>\n    }<br \/>\n    const T&amp; top()<br \/>\n    {<br \/>\n        return vector&lt;T&gt;::back();<br \/>\n    }<br \/>\n    bool empty()<br \/>\n    {<br \/>\n        return vector&lt;T&gt;::empty();<br \/>\n    }<br \/>\n};<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\n    bit::stack&lt;int&gt; st;<br \/>\n    st.push(1);<br \/>\n    st.push(2);<br \/>\n    st.push(3);<br \/>\n    while(!st.empty())<br \/>\n    {<br \/>\n        cout &lt;&lt; st.top() &lt;&lt; &#034; &#034;;<br \/>\n        st.pop();<br \/>\n    }<br \/>\n    return 0;<br \/>\n}<\/p>\n<h3 id=\"2.%20%E5%9F%BA%E7%B1%BB%E4%B8%8E%E6%B4%BE%E7%94%9F%E7%B1%BB%E5%AF%B9%E8%B1%A1%E8%BD%AC%E6%8D%A2%EF%BC%88%E5%88%87%E7%89%87%20%2F%20%E5%88%87%E5%89%B2%20slicing%EF%BC%89\">2. \u57fa\u7c7b\u4e0e\u6d3e\u751f\u7c7b\u5bf9\u8c61\u8f6c\u6362&#xff08;\u5207\u7247 \/ \u5207\u5272 slicing&#xff09;<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"241\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d2433e19b.png\" width=\"435\" \/><\/p>\n<p>\u53ea\u9488\u5bf9public \u516c\u6709\u7ee7\u627f<\/p>\n<li>\u6d3e\u751f\u7c7b\u5bf9\u8c61\u53ef\u4ee5\u8d4b\u503c\u7ed9\u57fa\u7c7b\u5bf9\u8c61\u3001\u57fa\u7c7b\u6307\u9488\u3001\u57fa\u7c7b\u5f15\u7528<\/li>\n<p>\u5207\u7247&#xff08;\u5207\u5272&#xff09;&#xff1a;\u628a\u6d3e\u751f\u7c7b\u5bf9\u8c61\u91cc\u9762\u5c5e\u4e8e\u57fa\u7c7b\u7684\u90a3\u4e00\u90e8\u5206\u5207\u51fa\u6765&#xff0c;\u4ea4\u7ed9\u57fa\u7c7b\u3002\u6d3e\u751f\u7c7b\u72ec\u6709\u7684\u6210\u5458\u76f4\u63a5\u88ab\u5207\u6389\u4e22\u5f03\u3002<\/p>\n<p>class Person<br \/>\n{<br \/>\nprotected:<br \/>\n    string _name;<br \/>\n    string _sex;<br \/>\n    int _age;<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\n    int _No; \/\/\u5b66\u53f7<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Student sobj;<\/p>\n<p>    \/\/1.\u6d3e\u751f\u7c7b \u2192 \u57fa\u7c7b\u6307\u9488<br \/>\n    Person* pp &#061; &amp;sobj;<br \/>\n    \/\/2.\u6d3e\u751f\u7c7b \u2192 \u57fa\u7c7b\u5f15\u7528<br \/>\n    Person&amp; rp &#061; sobj;<br \/>\n    \/\/3.\u6d3e\u751f\u7c7b\u8d4b\u503c\u7ed9\u57fa\u7c7b\u5bf9\u8c61&#xff08;\u53d1\u751f\u5bf9\u8c61\u5207\u7247&#xff0c;\u8c03\u7528\u57fa\u7c7b\u62f7\u8d1d\u6784\u9020&#xff09;<br \/>\n    Person pobj &#061; sobj;<\/p>\n<p>    \/\/ \u274c\u57fa\u7c7b\u5bf9\u8c61\u4e0d\u80fd\u76f4\u63a5\u8d4b\u503c\u7ed9\u6d3e\u751f\u7c7b\u5bf9\u8c61&#xff0c;\u7f16\u8bd1\u62a5\u9519<br \/>\n    \/\/ sobj &#061; pobj;<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<ul>\n<li>\u57fa\u7c7b\u666e\u901a\u5bf9\u8c61\u4e0d\u80fd\u76f4\u63a5\u8d4b\u503c\u7ed9\u6d3e\u751f\u7c7b\u5bf9\u8c61\u3002<\/li>\n<li>\u57fa\u7c7b\u6307\u9488\u5982\u679c\u672c\u6765\u6307\u5411\u6d3e\u751f\u7c7b\u5bf9\u8c61&#xff0c;\u53ef\u4ee5\u5f3a\u5236\u8f6c\u6362\u4e3a\u6d3e\u751f\u7c7b\u6307\u9488&#xff1b;\u5b89\u5168\u8f6c\u6362\u540e\u9762\u591a\u6001\u7ae0\u8282\u5b66\u4e60dynamic_cast\u3002<\/li>\n<\/ul>\n<h3 id=\"3.%20%E7%BB%A7%E6%89%BF%E4%BD%93%E7%B3%BB%E4%B8%8B%E4%BD%9C%E7%94%A8%E5%9F%9F%E4%B8%8E%E9%9A%90%E8%97%8F%EF%BC%88name%E2%80%91hiding%EF%BC%89\">3. \u7ee7\u627f\u4f53\u7cfb\u4e0b\u4f5c\u7528\u57df\u4e0e\u9690\u85cf&#xff08;name\u2011hiding&#xff09;<\/h3>\n<li>\u57fa\u7c7b\u3001\u6d3e\u751f\u7c7b\u62e5\u6709\u76f8\u4e92\u72ec\u7acb\u7684\u4f5c\u7528\u57df\u3002<\/li>\n<li>\u6210\u5458\u9690\u85cf&#xff08;\u906e\u853d&#xff09;&#xff1a;\u6d3e\u751f\u7c7b\u548c\u57fa\u7c7b\u51fa\u73b0\u540c\u540d\u6210\u5458&#xff0c;\u6d3e\u751f\u7c7b\u6210\u5458\u4f1a\u5c4f\u853d\u57fa\u7c7b\u540c\u540d\u6210\u5458\u3002<\/li>\n<p>\u6ce8\u610f&#xff1a;\u53ea\u8981\u51fd\u6570\u540d\u5b57\u4e00\u6837\u5c31\u6784\u6210\u9690\u85cf&#xff0c;\u53c2\u6570\u4e0d\u4e00\u6837\u4e5f\u9690\u85cf&#xff0c;\u4e0d\u662f\u91cd\u8f7d&#xff01;\u91cd\u8f7d\u53ea\u53d1\u751f\u5728\u540c\u4e00\u4e2a\u4f5c\u7528\u57df&#xff01;<\/p>\n<li>\u5982\u679c\u9700\u8981\u5728\u5b50\u7c7b\u8bbf\u95ee\u88ab\u9690\u85cf\u7684\u57fa\u7c7b\u6210\u5458&#xff0c;\u4f7f\u7528 \u57fa\u7c7b::\u6210\u5458\u540d\u663e\u5f0f\u6307\u5b9a\u7c7b\u57df\u3002<\/li>\n<p>\u5de5\u7a0b\u7f16\u7801\u5efa\u8bae&#xff1a;\u5c3d\u91cf\u4e0d\u8981\u5199\u540c\u540d\u6210\u5458&#xff0c;\u53ef\u8bfb\u6027\u5dee\u5bb9\u6613\u8e29\u5751\u3002<\/p>\n<h4 id=\"%E5%90%8C%E5%90%8D%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E9%9A%90%E8%97%8F%E7%A4%BA%E4%BE%8B\">\u540c\u540d\u6210\u5458\u53d8\u91cf\u9690\u85cf\u793a\u4f8b<\/h4>\n<p>class Person<br \/>\n{<br \/>\nprotected:<br \/>\n    string _name &#061; &#034;\u5c0f\u674e\u5b50&#034;;<br \/>\n    int _num &#061; 111; \/\/\u8eab\u4efd\u8bc1\u53f7<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\n    void Print()<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;\u59d3\u540d:&#034; &lt;&lt; _name &lt;&lt; endl;<br \/>\n        cout &lt;&lt; &#034;\u8eab\u4efd\u8bc1\u53f7:&#034; &lt;&lt; Person::_num &lt;&lt; endl; \/\/\u663e\u5f0f\u6307\u5b9a\u57fa\u7c7b\u57df\u8bbf\u95ee\u88ab\u9690\u85cf\u6210\u5458<br \/>\n        cout &lt;&lt; &#034;\u5b66\u53f7:&#034; &lt;&lt; _num &lt;&lt; endl;<br \/>\n    }<br \/>\nprotected:<br \/>\n    int _num &#061; 999; \/\/\u5b66\u53f7&#xff0c;\u548c\u7236\u7c7b_num\u540c\u540d&#xff0c;\u53d1\u751f\u9690\u85cf<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Student s1;<br \/>\n    s1.Print();<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4 id=\"%E5%90%8C%E5%90%8D%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0%E9%9A%90%E8%97%8F%EF%BC%88%E9%87%8D%E7%82%B9%E9%80%89%E6%8B%A9%E9%A2%98%EF%BC%89\">\u540c\u540d\u6210\u5458\u51fd\u6570\u9690\u85cf&#xff08;\u91cd\u70b9\u9009\u62e9\u9898&#xff09;<\/h4>\n<p>class A<br \/>\n{<br \/>\npublic:<br \/>\n    void fun()<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;A::fun()&#034; &lt;&lt; endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>class B : public A<br \/>\n{<br \/>\npublic:<br \/>\n    \/\/\u51fd\u6570\u540d\u5b57\u76f8\u540c&#xff0c;\u53c2\u6570\u4e0d\u540c&#xff0c;\u6784\u6210\u3010\u9690\u85cf\u3011&#xff0c;\u4e0d\u662f\u91cd\u8f7d&#xff01;<br \/>\n    void fun(int i)<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;B::fun(int i)&#034; &lt;&lt; i &lt;&lt; endl;<br \/>\n    }<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    B b;<br \/>\n    b.fun(10); \/\/\u8c03\u7528B::fun(int)<br \/>\n    \/\/ b.fun(); \/\/\u7f16\u8bd1\u62a5\u9519&#xff0c;\u5b50\u7c7b\u4f5c\u7528\u57df\u628a\u7236\u7c7bfun()\u9690\u85cf\u4e86&#xff01;<br \/>\n    b.A::fun(); \/\/\u60f3\u8981\u8c03\u7528\u7236\u7c7b\u7248\u672c&#xff0c;\u5fc5\u987b\u663e\u5f0f\u6307\u5b9a\u7c7b\u57df<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u8003\u70b9&#xff1a;\u91cd\u8f7d\u5fc5\u987b\u540c\u4e00\u4e2a\u7c7b\u540c\u4e00\u4e2a\u4f5c\u7528\u57df&#xff1b;\u7236\u5b50\u7c7b\u4e4b\u95f4\u540c\u540d\u51fd\u6570&#xff0c;\u4e0d\u7ba1\u53c2\u6570\u662f\u5426\u4e00\u6837&#xff0c;\u90fd\u662f\u9690\u85cf\u3002<\/p>\n<h3 id=\"4.%20%E6%B4%BE%E7%94%9F%E7%B1%BB%E7%9A%84%E9%BB%98%E8%AE%A4%206%20%E4%B8%AA%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0\">4. \u6d3e\u751f\u7c7b\u7684\u9ed8\u8ba4 6 \u4e2a\u6210\u5458\u51fd\u6570<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"262\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d243573f6.png\" width=\"827\" \/><\/p>\n<p>\u7f16\u8bd1\u5668\u5728\u6ee1\u8db3\u6761\u4ef6\u65f6\u81ea\u52a8\u751f\u6210 6 \u4e2a\u9ed8\u8ba4\u6210\u5458\u51fd\u6570&#xff1a;\u6784\u9020\u3001\u62f7\u8d1d\u6784\u9020\u3001\u8d4b\u503c\u8fd0\u7b97\u7b26\u91cd\u8f7d\u3001\u6790\u6784\u3001\u53d6\u5730\u5740\u4e24\u4e2a\u91cd\u8f7d\u3002<\/p>\n<h4 id=\"%E6%B4%BE%E7%94%9F%E7%B1%BB%E9%BB%98%E8%AE%A4%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0%E6%89%A7%E8%A1%8C%E8%A7%84%E5%88%99\">\u6d3e\u751f\u7c7b\u9ed8\u8ba4\u6210\u5458\u51fd\u6570\u6267\u884c\u89c4\u5219<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"295\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d2437ac94.png\" width=\"840\" \/><\/p>\n<li>\u6d3e\u751f\u7c7b\u6784\u9020\u51fd\u6570&#xff1a;\u521d\u59cb\u5316\u5217\u8868\u9636\u6bb5\u5fc5\u987b\u8c03\u7528\u57fa\u7c7b\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316\u7ee7\u627f\u8fc7\u6765\u7684\u57fa\u7c7b\u90e8\u5206&#xff1b; \u5982\u679c\u57fa\u7c7b\u6ca1\u6709\u65e0\u53c2\u9ed8\u8ba4\u6784\u9020&#xff0c;\u6d3e\u751f\u7c7b\u5fc5\u987b\u5728\u521d\u59cb\u5316\u5217\u8868\u663e\u5f0f\u8c03\u7528\u5bf9\u5e94\u57fa\u7c7b\u6784\u9020\u3002<\/li>\n<p>\u5bf9\u8c61\u6784\u9020\u987a\u5e8f&#xff1a;\u5148\u57fa\u7c7b\u6784\u9020&#xff0c;\u518d\u6d3e\u751f\u7c7b\u6784\u9020\u3002<\/p>\n<li>\u6d3e\u751f\u7c7b\u62f7\u8d1d\u6784\u9020&#xff1a;\u5fc5\u987b\u8c03\u7528\u57fa\u7c7b\u62f7\u8d1d\u6784\u9020&#xff0c;\u5b8c\u6210\u57fa\u7c7b\u90e8\u5206\u62f7\u8d1d\u3002<\/li>\n<li>\u6d3e\u751f\u7c7b operator &#061; \u8d4b\u503c\u91cd\u8f7d&#xff1a;\u5fc5\u987b\u8c03\u7528\u57fa\u7c7b\u7684\u8d4b\u503c\u91cd\u8f7d&#xff1b;\u6d3e\u751f\u7c7b\u4f1a\u9690\u85cf\u57fa\u7c7b\u7684 operator&#061;&#xff0c;\u9700\u8981\u663e\u5f0f\u57fa\u7c7b::operator&#061;(s)\u8c03\u7528\u3002<\/li>\n<li>\u6d3e\u751f\u7c7b\u6790\u6784\u51fd\u6570&#xff1a;\u6d3e\u751f\u7c7b\u6790\u6784\u6267\u884c\u5b8c\u6bd5&#xff0c;\u7f16\u8bd1\u5668\u81ea\u52a8\u8c03\u7528\u57fa\u7c7b\u6790\u6784&#xff1b;<\/li>\n<p>\u5bf9\u8c61\u6790\u6784\u987a\u5e8f&#xff1a;\u5148\u6d3e\u751f\u7c7b\u6790\u6784&#xff0c;\u518d\u57fa\u7c7b\u6790\u6784&#xff0c;\u548c\u6784\u9020\u987a\u5e8f\u76f8\u53cd\u3002<\/p>\n<li>\u6790\u6784\u51fd\u6570\u540d\u5b57\u4f1a\u88ab\u7f16\u8bd1\u5668\u7279\u6b8a\u5904\u7406\u4e3adestructor()&#xff0c;\u57fa\u7c7b\u548c\u6d3e\u751f\u7c7b\u6790\u6784\u51fd\u6570\u540d\u5b57\u4e0d\u4e00\u6837&#xff0c;\u666e\u901a\u7ee7\u627f\u4e0b\u6784\u6210\u9690\u85cf&#xff0c;\u4e0d\u662f\u91cd\u5199&#xff1b;\u591a\u6001\u7ae0\u8282 virtual \u865a\u6790\u6784\u624d\u4f1a\u91cd\u5199\u3002<\/li>\n<p>\u5b8c\u6574\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\n    Person(const char* name &#061; &#034;peter&#034;)<br \/>\n        :_name(name)<br \/>\n    {<br \/>\n        cout &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 \/>\n        cout &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 \/>\n        cout &lt;&lt; &#034;Person operator&#061;(const Person&amp; p)&#034; &lt;&lt; endl;<br \/>\n        if(this !&#061; &amp;p)<br \/>\n        {<br \/>\n            _name &#061; p._name;<br \/>\n        }<br \/>\n        return *this;<br \/>\n    }<\/p>\n<p>    ~Person()<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;~Person()&#034; &lt;&lt; endl;<br \/>\n    }<br \/>\nprotected:<br \/>\n    string _name;<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\npublic:<br \/>\n    \/\/\u6d3e\u751f\u7c7b\u6784\u9020&#xff1a;\u521d\u59cb\u5316\u5217\u8868\u8c03\u7528\u57fa\u7c7b\u6784\u9020<br \/>\n    Student(const char* name, int num)<br \/>\n        : Person(name)<br \/>\n        , _num(num)<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;Student()&#034; &lt;&lt; endl;<br \/>\n    }<\/p>\n<p>    \/\/\u6d3e\u751f\u7c7b\u62f7\u8d1d\u6784\u9020&#xff0c;\u8c03\u7528\u57fa\u7c7b\u62f7\u8d1d\u6784\u9020<br \/>\n    Student(const Student&amp; s)<br \/>\n        : Person(s)<br \/>\n        , _num(s._num)<br \/>\n    {<br \/>\n        cout &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 \/>\n        cout &lt;&lt; &#034;Student&amp; operator&#061;(const Student&amp; s)&#034; &lt;&lt; endl;<br \/>\n        if(this !&#061; &amp;s)<br \/>\n        {<br \/>\n            \/\/\u663e\u5f0f\u8c03\u7528\u57fa\u7c7b\u8d4b\u503c\u91cd\u8f7d&#xff0c;\u6d3e\u751f\u7c7b\u4f1a\u9690\u85cf\u57fa\u7c7boperator&#061;<br \/>\n            Person::operator&#061;(s);<br \/>\n            _num &#061; s._num;<br \/>\n        }<br \/>\n        return *this;<br \/>\n    }<\/p>\n<p>    ~Student()<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;~Student()&#034; &lt;&lt; endl;<br \/>\n        \/\/\u7f16\u8bd1\u5668\u81ea\u52a8\u5728\u51fd\u6570\u672b\u5c3e\u8c03\u7528 ~Person()&#xff0c;\u4e0d\u9700\u8981\u624b\u5199<br \/>\n    }<br \/>\nprotected:<br \/>\n    int _num;<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Student s1(&#034;jack&#034;,18);<br \/>\n    Student s2(s1);<br \/>\n    Student s3(&#034;rose&#034;,17);<br \/>\n    s1 &#061; s3;<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4 id=\"4.2%20%E7%A6%81%E6%AD%A2%E7%B1%BB%E8%A2%AB%E7%BB%A7%E6%89%BF%E4%B8%A4%E7%A7%8D%E5%86%99%E6%B3%95\">4.2 \u7981\u6b62\u7c7b\u88ab\u7ee7\u627f\u4e24\u79cd\u5199\u6cd5<\/h4>\n<li>C&#043;&#043;11 final\u5173\u952e\u5b57\u4fee\u9970\u7c7b&#xff0c;\u8be5\u7c7b\u4e0d\u80fd\u88ab\u7ee7\u627f&#xff08;\u63a8\u8350&#xff09;<\/li>\n<p>class Base final<br \/>\n{<br \/>\npublic:<br \/>\n    void func5() { cout &lt;&lt; &#034;Base::func5&#034; &lt;&lt; endl; }<br \/>\nprotected:<br \/>\n    int a &#061; 1;<br \/>\n};<br \/>\n\/\/ class Derive : public Base{}; \/\/\u7f16\u8bd1\u62a5\u9519&#xff0c;Base\u88abfinal\u7981\u6b62\u7ee7\u627f<\/p>\n<li>C&#043;&#043;98 \u65e7\u65b9\u5f0f&#xff1a;\u628a\u57fa\u7c7b\u6784\u9020\u51fd\u6570\u8bbe\u7f6e\u4e3a private\u3002\u6d3e\u751f\u7c7b\u5b9e\u4f8b\u5316\u5bf9\u8c61\u5fc5\u987b\u8c03\u7528\u57fa\u7c7b\u6784\u9020&#xff0c;\u57fa\u7c7b\u6784\u9020\u79c1\u6709\u5b50\u7c7b\u65e0\u6cd5\u8bbf\u95ee&#xff0c;\u5b50\u7c7b\u4e0d\u80fd\u5b9e\u4f8b\u5316\u3002<\/li>\n<h3 id=\"5.%20%E7%BB%A7%E6%89%BF%E4%B8%8E%E5%8F%8B%E5%85%83\">5. \u7ee7\u627f\u4e0e\u53cb\u5143<\/h3>\n<p>\u2757\u53cb\u5143\u5173\u7cfb\u4e0d\u4f1a\u7ee7\u627f\u3002\u57fa\u7c7b\u7684\u53cb\u5143\u51fd\u6570&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u6d3e\u751f\u7c7b\u7684 protected\/private \u6210\u5458\u3002<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>class Student;<br \/>\nclass Person<br \/>\n{<br \/>\npublic:<br \/>\n    friend void Display(const Person&amp; p, const Student&amp; s);<br \/>\nprotected:<br \/>\n    string _name;<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\nprotected:<br \/>\n    int _stuNum;<br \/>\n};<\/p>\n<p>void Display(const Person&amp; p, const Student&amp; s)<br \/>\n{<br \/>\n    cout &lt;&lt; p._name &lt;&lt; endl;<br \/>\n    \/\/ cout &lt;&lt; s._stuNum &lt;&lt; endl; \/\/\u7f16\u8bd1\u62a5\u9519&#xff01;\u53cb\u5143\u4e0d\u7ee7\u627f&#xff0c;\u4e0d\u80fd\u8bbf\u95eeStudent\u7684_stuNum<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Person p;<br \/>\n    Student s;<br \/>\n    \/\/ Display(p,s); \/\/\u62a5\u9519<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u89e3\u51b3&#xff1a;\u9700\u8981\u628a Display \u4e5f\u8bbe\u7f6e\u4e3a Student \u7684\u53cb\u5143\u3002<\/p>\n<h3 id=\"6.%20%E7%BB%A7%E6%89%BF%E4%B8%8E%E9%9D%99%E6%80%81%E6%88%90%E5%91%98\">6. \u7ee7\u627f\u4e0e\u9759\u6001\u6210\u5458<\/h3>\n<p>\u57fa\u7c7b\u91cc\u9762\u7684 static \u9759\u6001\u6210\u5458&#xff0c;\u6574\u4e2a\u7ee7\u627f\u4f53\u7cfb\u4e4b\u5185\u53ea\u6709\u552f\u4e00\u4e00\u4efd&#xff0c;\u6240\u6709\u6d3e\u751f\u7c7b\u5bf9\u8c61\u5171\u4eab\u540c\u4e00\u4efd\u9759\u6001\u6210\u5458\u3002 \u53ef\u4ee5\u901a\u8fc7\u57fa\u7c7b\u540d\u3001\u6d3e\u751f\u7c7b\u540d\u8bbf\u95ee public \u9759\u6001\u6210\u5458\u3002<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\n    string _name;<br \/>\n    static int _count;<br \/>\n};<br \/>\nint Person::_count &#061; 0;<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\nprotected:<br \/>\n    int _stuNum;<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Person p;<br \/>\n    Student s;<\/p>\n<p>    cout &lt;&lt; &amp;p._name &lt;&lt; endl; \/\/\u666e\u901a\u6210\u5458\u6bcf\u4e2a\u5bf9\u8c61\u72ec\u7acb\u4e00\u4efd&#xff0c;\u5730\u5740\u4e0d\u540c<br \/>\n    cout &lt;&lt; &amp;s._name &lt;&lt; endl;<\/p>\n<p>    cout &lt;&lt; &amp;p._count &lt;&lt; endl;<br \/>\n    cout &lt;&lt; &amp;s._count &lt;&lt; endl; \/\/\u9759\u6001\u6210\u5458\u5730\u5740\u5b8c\u5168\u76f8\u540c&#xff0c;\u5171\u4eab\u540c\u4e00\u4efd<\/p>\n<p>    cout &lt;&lt; Person::_count &lt;&lt; endl;<br \/>\n    cout &lt;&lt; Student::_count &lt;&lt; endl;<br \/>\n    return 0;<br \/>\n}<\/p>\n<h3 id=\"7.%20%E5%A4%9A%E7%BB%A7%E6%89%BF%E3%80%81%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF%E4%B8%8E%E8%99%9A%E7%BB%A7%E6%89%BF%20virtual\">7. \u591a\u7ee7\u627f\u3001\u83f1\u5f62\u7ee7\u627f\u4e0e\u865a\u7ee7\u627f virtual<\/h3>\n<h4 id=\"7.1%20%E5%8D%95%E7%BB%A7%E6%89%BF%E3%80%81%E5%A4%9A%E7%BB%A7%E6%89%BF\">7.1 \u5355\u7ee7\u627f\u3001\u591a\u7ee7\u627f<\/h4>\n<ul>\n<li>\u5355\u7ee7\u627f&#xff1a;\u4e00\u4e2a\u6d3e\u751f\u7c7b\u53ea\u6709\u4e00\u4e2a\u76f4\u63a5\u57fa\u7c7b\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"268\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d2439ed90.png\" width=\"433\" \/><\/p>\n<ul>\n<li>\u591a\u7ee7\u627f&#xff1a;\u4e00\u4e2a\u6d3e\u751f\u7c7b\u62e5\u6709\u4e24\u4e2a\u53ca\u4ee5\u4e0a\u76f4\u63a5\u57fa\u7c7b\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"220\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d243b9385.png\" width=\"492\" \/><\/p>\n<p>\u5bf9\u8c61\u5185\u5b58\u6392\u5e03&#xff1a;\u7ee7\u627f\u5217\u8868\u4ece\u5de6\u5230\u53f3&#xff0c;\u5148\u7ee7\u627f\u7684\u57fa\u7c7b\u653e\u5728\u5185\u5b58\u4f4e\u5730\u5740&#xff0c;\u540e\u7ee7\u627f\u653e\u540e\u9762&#xff0c;\u6d3e\u751f\u7c7b\u81ea\u5df1\u6210\u5458\u653e\u6700\u540e\u3002<\/p>\n<h4 id=\"7.2%20%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF%EF%BC%88%E9%92%BB%E7%9F%B3%E7%BB%A7%E6%89%BF%EF%BC%89%E2%80%94%E2%80%94%20%E5%A4%9A%E7%BB%A7%E6%89%BF%E7%89%B9%E6%AE%8A%E5%9D%91\">7.2 \u83f1\u5f62\u7ee7\u627f&#xff08;\u94bb\u77f3\u7ee7\u627f&#xff09;\u2014\u2014 \u591a\u7ee7\u627f\u7279\u6b8a\u5751<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"351\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d243d272a.png\" width=\"691\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"452\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190851-6ab2d243ef0bc.png\" width=\"446\" \/><\/p>\n<p>\u7ee7\u627f\u5173\u7cfb&#xff1a;Assistant\u52a9\u7406\u540c\u65f6\u7ee7\u627fStudent\u548cTeacher&#xff1b;Student\u3001Teacher \u90fd\u7ee7\u627f Person\u3002<\/p>\n<p>\u95ee\u9898&#xff1a;<\/p>\n<li>\u6570\u636e\u5197\u4f59&#xff1a;Assistant \u5bf9\u8c61\u91cc\u9762\u4f1a\u5b58\u5728\u4e24\u4efd Person \u57fa\u7c7b\u6570\u636e&#xff08;\u4e00\u4efd\u6765\u81ea Student \u8def\u5f84&#xff0c;\u4e00\u4efd\u6765\u81ea Teacher \u8def\u5f84&#xff09;&#xff1b;<\/li>\n<li>\u4e8c\u4e49\u6027&#xff1a;\u76f4\u63a5\u8bbf\u95eeAssistant._name\u7f16\u8bd1\u5668\u4e0d\u77e5\u9053\u8d70\u54ea\u4e00\u6761\u7ee7\u627f\u8def\u5f84&#xff0c;\u7f16\u8bd1\u62a5\u9519\u3002<\/li>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\n    string _name;<br \/>\n};<\/p>\n<p>class Student : public Person<br \/>\n{<br \/>\nprotected:<br \/>\n    int _num; \/\/\u5b66\u53f7<br \/>\n};<\/p>\n<p>class Teacher : public Person<br \/>\n{<br \/>\nprotected:<br \/>\n    int _id; \/\/\u804c\u5de5\u7f16\u53f7<br \/>\n};<\/p>\n<p>\/\/\u52a9\u7406&#xff0c;\u591a\u7ee7\u627f Student\u3001Teacher<br \/>\nclass Assistant : public Student, public Teacher<br \/>\n{<br \/>\nprotected:<br \/>\n    string _majorCourse;<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Assistant a;<br \/>\n    \/\/ a._name &#061; &#034;peter&#034;; \/\/\u7f16\u8bd1\u62a5\u9519&#xff0c;\u4e8c\u4e49\u6027&#xff01;\u4e24\u4efd_name\u4e0d\u77e5\u9053\u9009\u54ea\u4e00\u4e2a<br \/>\n    \/\/\u5f3a\u5236\u6307\u5b9a\u8def\u5f84\u53ef\u4ee5\u8bbf\u95ee&#xff0c;\u4f46\u662f\u4e0d\u80fd\u89e3\u51b3\u6570\u636e\u5197\u4f59<br \/>\n    a.Student::_name &#061; &#034;xxx&#034;;<br \/>\n    a.Teacher::_name &#061; &#034;yyy&#034;;<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4 id=\"7.3%20%E8%99%9A%E7%BB%A7%E6%89%BF%20virtual%20%E8%A7%A3%E5%86%B3%E8%8F%B1%E5%BD%A2%E7%BB%A7%E6%89%BF\">7.3 \u865a\u7ee7\u627f virtual \u89e3\u51b3\u83f1\u5f62\u7ee7\u627f<\/h4>\n<p>\u5728\u4e2d\u95f4\u5c42\u7ee7\u627f\u7684\u65f6\u5019\u5199virtual public Person\u865a\u7ee7\u627f&#xff1b;\u516c\u5171\u7236\u7c7b Person \u5728\u5b50\u7c7b\u5bf9\u8c61\u91cc\u9762\u53ea\u4fdd\u5b58\u552f\u4e00\u4e00\u4efd&#xff0c;\u6d88\u9664\u5197\u4f59\u548c\u4e8c\u4e49\u6027\u3002<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>class Person<br \/>\n{<br \/>\npublic:<br \/>\n    string _name;<br \/>\n};<\/p>\n<p>\/\/\u865a\u7ee7\u627f<br \/>\nclass Student : virtual public Person<br \/>\n{<br \/>\nprotected:<br \/>\n    int _num;<br \/>\n};<\/p>\n<p>\/\/\u865a\u7ee7\u627f<br \/>\nclass Teacher : virtual public Person<br \/>\n{<br \/>\nprotected:<br \/>\n    int _id;<br \/>\n};<\/p>\n<p>class Assistant : public Student, public Teacher<br \/>\n{<br \/>\nprotected:<br \/>\n    string _majorCourse;<br \/>\n};<\/p>\n<p>int main()<br \/>\n{<br \/>\n    Assistant a;<br \/>\n    a._name &#061; &#034;peter&#034;; \/\/\u4e0d\u518d\u4e8c\u4e49\u6027&#xff0c;\u53ea\u6709\u552f\u4e00\u4e00\u4efdPerson<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u26a0\ufe0f\u6ce8\u610f&#xff1a;\u865a\u7ee7\u627f\u4f1a\u5f15\u5165\u865a\u57fa\u8868&#xff0c;\u5e95\u5c42\u5b9e\u73b0\u590d\u6742&#xff0c;\u6709\u4e00\u5b9a\u6027\u80fd\u5f00\u9500&#xff1b;\u5de5\u7a0b\u5c3d\u91cf\u4e0d\u8981\u8bbe\u8ba1\u83f1\u5f62\u7ee7\u627f\u3002Java \u76f4\u63a5\u53d6\u6d88\u591a\u7ee7\u627f\u4ece\u6839\u6e90\u89c4\u907f\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u6269\u5c55&#xff1a;C&#043;&#043; \u6807\u51c6 IO \u5e93ios_base\u5c31\u662f\u5178\u578b\u865a\u7ee7\u627f\u83f1\u5f62\u7ed3\u6784\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"377\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190852-6ab2d24419087.png\" width=\"549\" \/><\/p>\n<h3 id=\"8.%20%E7%BB%A7%E6%89%BF%E4%B8%8E%E7%BB%84%E5%90%88\">8. \u7ee7\u627f\u4e0e\u7ec4\u5408<\/h3>\n<h4 id=\"8.1%20is%E2%80%91a%20vs%20has%E2%80%91a\">8.1 is\u2011a vs has\u2011a<\/h4>\n<li>public \u7ee7\u627f&#xff1a;is\u2011a \u662f\u4e00\u4e2a<\/li>\n<p>Student is\u2011a Person&#xff1b;BMW is\u2011a Car\u3002 \u7ee7\u627f\u5c5e\u4e8e\u767d\u7bb1\u590d\u7528&#xff1a;\u57fa\u7c7b\u5185\u90e8\u7ec6\u8282\u5bf9\u5b50\u7c7b\u53ef\u89c1&#xff1b;\u7236\u5b50\u7c7b\u8026\u5408\u5ea6\u5f88\u9ad8&#xff0c;\u57fa\u7c7b\u6539\u52a8\u4f1a\u5f3a\u70c8\u5f71\u54cd\u5b50\u7c7b\u3002<\/p>\n<li>\u7ec4\u5408&#xff1a;has\u2011a \u62e5\u6709\u4e00\u4e2a<\/li>\n<p>Car has\u2011a Tire&#xff08;\u6c7d\u8f66\u62e5\u6709\u8f6e\u80ce&#xff09;\u3002\u628a\u522b\u7684\u7c7b\u4f5c\u4e3a\u81ea\u5df1\u7684\u6210\u5458\u53d8\u91cf\u3002 \u7ec4\u5408\u5c5e\u4e8e\u9ed1\u7bb1\u590d\u7528&#xff0c;\u53ea\u4f7f\u7528\u5bf9\u65b9\u516c\u5f00\u63a5\u53e3&#xff0c;\u5185\u90e8\u7ec6\u8282\u4e0d\u53ef\u89c1&#xff1b;\u8026\u5408\u4f4e&#xff0c;\u7ef4\u62a4\u6027\u66f4\u597d\u3002<\/p>\n<p>\u2728\u5f00\u53d1\u7ecf\u9a8c&#xff1a;\u4f18\u5148\u4f7f\u7528\u7ec4\u5408&#xff1b;\u53ea\u6709\u6ee1\u8db3 is\u2011a \u8bed\u4e49\u518d\u7528\u7ee7\u627f&#xff1b;\u5b9e\u73b0\u591a\u6001\u5fc5\u987b\u4f7f\u7528\u7ee7\u627f\u3002<\/p>\n<p>\u793a\u4f8b\u5bf9\u6bd4 stack \u4e24\u79cd\u5b9e\u73b0&#xff1a;<\/p>\n<p>\/\/\u65b9\u5f0f1&#xff1a;\u7ee7\u627f vector is\u2011a&#xff08;\u4e0d\u63a8\u8350&#xff09;<br \/>\ntemplate&lt;class T&gt;<br \/>\nclass stack : public std::vector&lt;T&gt;<br \/>\n{};<\/p>\n<p>\/\/\u65b9\u5f0f2&#xff1a;\u7ec4\u5408 has\u2011a&#xff08;\u63a8\u8350&#xff0c;\u5bb9\u5668\u9002\u914d\u5668\u771f\u5b9e\u5b9e\u73b0\u601d\u8def&#xff09;<br \/>\ntemplate&lt;class T&gt;<br \/>\nclass stack<br \/>\n{<br \/>\npublic:<br \/>\n    std::vector&lt;T&gt; _v;<br \/>\n};<\/p>\n<h3 id=\"%F0%9F%93%94%E6%9C%AC%E7%AF%87%E6%A0%B8%E5%BF%83%E8%80%83%E7%82%B9%E6%80%BB%E7%BB%93\">&#x1f4d4;\u672c\u7bc7\u6838\u5fc3\u8003\u70b9\u603b\u7ed3<\/h3>\n<li>\u7ee7\u627f\u5b9e\u73b0\u7c7b\u5c42\u6b21\u4ee3\u7801\u590d\u7528&#xff1b;\u4e09\u79cd\u7ee7\u627f\u65b9\u5f0fpublic\/protected\/private&#xff1b;\u57fa\u7c7b private \u6210\u5458\u5b50\u7c7b\u6c38\u8fdc\u4e0d\u53ef\u89c1&#xff1b;\u53e3\u8bc0min(\u6210\u5458\u6743\u9650,\u7ee7\u627f\u65b9\u5f0f)\u3002\u5f00\u53d1\u53ea\u7528 public \u7ee7\u627f\u3002<\/li>\n<li>\u6d3e\u751f\u7c7b\u5bf9\u8c61\u5207\u7247&#xff1a;\u6d3e\u751f\u7c7b\u53ef\u4ee5\u8d4b\u503c\u7ed9\u57fa\u7c7b\u6307\u9488 \/ \u5f15\u7528 \/ \u5bf9\u8c61&#xff1b;\u57fa\u7c7b\u4e0d\u80fd\u76f4\u63a5\u8d4b\u503c\u7ed9\u6d3e\u751f\u7c7b\u3002<\/li>\n<li>\u7236\u5b50\u7c7b\u540c\u540d\u6210\u5458\u6784\u6210\u9690\u85cf name\u2011hiding&#xff0c;\u4e0d\u662f\u91cd\u8f7d&#xff0c;\u91cd\u8f7d\u4ec5\u9650\u540c\u4e00\u4e2a\u4f5c\u7528\u57df&#xff1b;\u57fa\u7c7b::\u6210\u5458\u8bbf\u95ee\u88ab\u9690\u85cf\u6210\u5458\u3002<\/li>\n<li>\u9ed8\u8ba4\u6210\u5458\u51fd\u6570&#xff1a;\u6784\u9020\u5148\u57fa\u7c7b\u540e\u6d3e\u751f\u7c7b&#xff1b;\u6790\u6784\u5148\u6d3e\u751f\u7c7b\u540e\u57fa\u7c7b&#xff1b;\u62f7\u8d1d\u6784\u9020\u3001\u8d4b\u503c\u91cd\u8f7d\u8981\u5904\u7406\u57fa\u7c7b\u90e8\u5206\u3002final \u4fee\u9970\u7c7b\u7981\u6b62\u7ee7\u627f\u3002<\/li>\n<li>\u53cb\u5143\u4e0d\u80fd\u7ee7\u627f&#xff1b;static \u9759\u6001\u6210\u5458\u7ee7\u627f\u4f53\u7cfb\u5171\u4eab\u540c\u4e00\u4efd\u3002<\/li>\n<li>\u591a\u7ee7\u627f\u4f1a\u5e26\u6765\u83f1\u5f62\u7ee7\u627f&#xff1a;\u4e24\u4efd\u516c\u5171\u57fa\u7c7b&#xff0c;\u6570\u636e\u5197\u4f59 &#043; \u8bbf\u95ee\u4e8c\u4e49\u6027&#xff1b;virtual\u865a\u7ee7\u627f\u89e3\u51b3&#xff1b;\u5c3d\u91cf\u907f\u514d\u83f1\u5f62\u7ee7\u627f\u3002<\/li>\n<li>is\u2011a \u7528\u7ee7\u627f&#xff0c;has\u2011a \u4f18\u5148\u7528\u7ec4\u5408&#xff1b;\u7ec4\u5408\u8026\u5408\u4f4e&#xff0c;\u4f18\u5148\u7ec4\u5408\u3002<\/li>\n<p>\u9762\u8bd5\u7b80\u7b54<\/p>\n<p>Q&#xff1a;\u57fa\u7c7b private \u6210\u5458\u5b50\u7c7b\u80fd\u4e0d\u80fd\u7ee7\u627f&#xff1f;\u80fd\u4e0d\u80fd\u8bbf\u95ee&#xff1f;<\/p>\n<p>A&#xff1a;\u5185\u5b58\u4e0a\u7ee7\u627f\u5230\u5b50\u7c7b\u5bf9\u8c61&#xff0c;\u4f46\u662f\u8bed\u6cd5\u4e0d\u53ef\u8bbf\u95ee&#xff1b;\u5b50\u7c7b\u9700\u8981\u8bbf\u95ee\u5c31\u8bbe\u7f6e\u4e3a protected\u3002<\/p>\n<\/p>\n<p>Q&#xff1a;\u6210\u5458\u9690\u85cf\u548c\u91cd\u8f7d\u533a\u522b&#xff1f;<\/p>\n<p>A&#xff1a;\u91cd\u8f7d\u5728\u540c\u4e00\u4e2a\u4f5c\u7528\u57df&#xff0c;\u51fd\u6570\u540d\u76f8\u540c\u53c2\u6570\u4e0d\u540c&#xff1b;\u7236\u5b50\u4e0d\u540c\u4f5c\u7528\u57df\u53ea\u8981\u540d\u5b57\u76f8\u540c\u5c31\u662f\u9690\u85cf&#xff0c;\u548c\u53c2\u6570\u65e0\u5173\u3002<\/p>\n<\/p>\n<p>Q&#xff1a;\u83f1\u5f62\u7ee7\u627f\u95ee\u9898\u600e\u4e48\u89e3\u51b3&#xff1f;<\/p>\n<p>A&#xff1a;\u4e2d\u95f4\u5c42\u4f7f\u7528 virtual \u865a\u7ee7\u627f&#xff1b;\u6700\u597d\u8bbe\u8ba1\u4e0a\u907f\u514d\u83f1\u5f62\u7ee7\u627f\u3002<\/p>\n<\/p>\n<p>Q&#xff1a;\u7ee7\u627f\u548c\u7ec4\u5408\u600e\u4e48\u9009&#xff1f;<\/p>\n<p>A&#xff1a;is\u2011a \u662f\u7ee7\u627f&#xff1b;has\u2011a \u4f18\u5148\u7ec4\u5408&#xff0c;\u7ec4\u5408\u8026\u5408\u66f4\u4f4e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"624\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190852-6ab2d24437e16.jpg\" width=\"2048\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u200b\u7f16\u8f91<br \/>\n\u672c\u8282\u5b66\u4e60\u76ee\u6807<br \/>\n1. \u7ee7\u627f\u7684\u6982\u5ff5\u53ca\u5b9a\u4e49<br \/>\n1.1 \u4ec0\u4e48\u662f\u7ee7\u627f<br \/>\n1.2 \u7ee7\u627f\u5b9a\u4e49\u8bed\u6cd5<br \/>\n\u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u7684\u8bbf\u95ee\u89c4\u5219<br \/>\n1.3 \u7ee7\u627f\u6a21\u677f\u7c7b&#xff08;\u6a21\u677f\u7236\u7c7b&#xff09;<br \/>\n2. \u57fa\u7c7b\u4e0e\u6d3e\u751f\u7c7b\u5bf9\u8c61\u8f6c\u6362&#xff08;\u5207\u7247 \/ \u5207\u5272 slicing&#xff09;<br \/>\n3. \u7ee7\u627f\u4f53\u7cfb\u4e0b\u4f5c\u7528\u57df\u4e0e\u9690\u85cf&#xff08;name\u2011hiding&#xff09;<br \/>\n\u540c\u540d\u6210\u5458\u53d8\u91cf\u9690\u85cf\u793a\u4f8b<br \/>\n\u540c\u540d\u6210\u5458\u51fd\u6570\u9690\u85cf&#xff08;\u91cd\u70b9\u9009\u62e9\u9898&#xff09;<br \/>\n4. \u6d3e\u751f\u7c7b\u7684\u9ed8\u8ba4 <\/p>\n","protected":false},"author":2,"featured_media":108950,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,2908,190],"topic":[],"class_list":["post-108963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-vs","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++\u8fdb\u9636\u3011\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\/108963.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++\u8fdb\u9636\u3011\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u200b\u7f16\u8f91 \u672c\u8282\u5b66\u4e60\u76ee\u6807 1. \u7ee7\u627f\u7684\u6982\u5ff5\u53ca\u5b9a\u4e49 1.1 \u4ec0\u4e48\u662f\u7ee7\u627f 1.2 \u7ee7\u627f\u5b9a\u4e49\u8bed\u6cd5 \u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u7684\u8bbf\u95ee\u89c4\u5219 1.3 \u7ee7\u627f\u6a21\u677f\u7c7b&#xff08;\u6a21\u677f\u7236\u7c7b&#xff09; 2. \u57fa\u7c7b\u4e0e\u6d3e\u751f\u7c7b\u5bf9\u8c61\u8f6c\u6362&#xff08;\u5207\u7247 \/ \u5207\u5272 slicing&#xff09; 3. \u7ee7\u627f\u4f53\u7cfb\u4e0b\u4f5c\u7528\u57df\u4e0e\u9690\u85cf&#xff08;name\u2011hiding&#xff09; \u540c\u540d\u6210\u5458\u53d8\u91cf\u9690\u85cf\u793a\u4f8b \u540c\u540d\u6210\u5458\u51fd\u6570\u9690\u85cf&#xff08;\u91cd\u70b9\u9009\u62e9\u9898&#xff09; 4. \u6d3e\u751f\u7c7b\u7684\u9ed8\u8ba4\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/108963.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-22T19:08:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190849-6ab2d241dabe4.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=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108963.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/108963.html\",\"name\":\"\u3010C++\u8fdb\u9636\u3011\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-22T19:08:53+00:00\",\"dateModified\":\"2026-09-22T19:08:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/108963.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/108963.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108963.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++\u8fdb\u9636\u3011\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++\u8fdb\u9636\u3011\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\/108963.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++\u8fdb\u9636\u3011\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u200b\u7f16\u8f91 \u672c\u8282\u5b66\u4e60\u76ee\u6807 1. \u7ee7\u627f\u7684\u6982\u5ff5\u53ca\u5b9a\u4e49 1.1 \u4ec0\u4e48\u662f\u7ee7\u627f 1.2 \u7ee7\u627f\u5b9a\u4e49\u8bed\u6cd5 \u57fa\u7c7b\u6210\u5458\u5728\u6d3e\u751f\u7c7b\u7684\u8bbf\u95ee\u89c4\u5219 1.3 \u7ee7\u627f\u6a21\u677f\u7c7b&#xff08;\u6a21\u677f\u7236\u7c7b&#xff09; 2. \u57fa\u7c7b\u4e0e\u6d3e\u751f\u7c7b\u5bf9\u8c61\u8f6c\u6362&#xff08;\u5207\u7247 \/ \u5207\u5272 slicing&#xff09; 3. \u7ee7\u627f\u4f53\u7cfb\u4e0b\u4f5c\u7528\u57df\u4e0e\u9690\u85cf&#xff08;name\u2011hiding&#xff09; \u540c\u540d\u6210\u5458\u53d8\u91cf\u9690\u85cf\u793a\u4f8b \u540c\u540d\u6210\u5458\u51fd\u6570\u9690\u85cf&#xff08;\u91cd\u70b9\u9009\u62e9\u9898&#xff09; 4. \u6d3e\u751f\u7c7b\u7684\u9ed8\u8ba4","og_url":"https:\/\/www.wsisp.com\/helps\/108963.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-22T19:08:53+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922190849-6ab2d241dabe4.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/108963.html","url":"https:\/\/www.wsisp.com\/helps\/108963.html","name":"\u3010C++\u8fdb\u9636\u3011\u7ee7\u627f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-22T19:08:53+00:00","dateModified":"2026-09-22T19:08:53+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/108963.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/108963.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/108963.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++\u8fdb\u9636\u3011\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\/108963","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=108963"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/108963\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/108950"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=108963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=108963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=108963"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=108963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}