{"id":1474,"date":"2018-06-28T01:42:44","date_gmt":"2018-06-27T17:42:44","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=1474"},"modified":"2018-06-28T01:42:44","modified_gmt":"2018-06-27T17:42:44","slug":"c-%e8%99%9a%e5%87%bd%e6%95%b0%e8%a1%a8%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/1474","title":{"rendered":"C++\u00a0\u865a\u51fd\u6570\u8868\u89e3\u6790"},"content":{"rendered":"<p style=\"font-weight: 400;\"><b><strong><i>\u9648\u7693<\/i><\/strong><\/b><\/p>\n<p style=\"font-weight: 400;\"><a href=\"http:\/\/blog.csdn.net\/haoel\">http:\/\/blog.csdn.net\/haoel<\/a><\/p>\n<p style=\"font-weight: 400;\">\n<h1><i>\u524d\u8a00<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">C++<i>\u4e2d\u7684\u865a\u51fd\u6570\u7684\u4f5c\u7528\u4e3b\u8981\u662f\u5b9e\u73b0\u4e86\u591a\u6001\u7684\u673a\u5236\u3002\u5173\u4e8e\u591a\u6001\uff0c\u7b80\u800c\u8a00\u4e4b\u5c31\u662f\u7528\u7236\u7c7b\u578b\u522b\u7684\u6307\u9488\u6307\u5411\u5176\u5b50\u7c7b\u7684\u5b9e\u4f8b\uff0c\u7136\u540e\u901a\u8fc7\u7236\u7c7b\u7684\u6307\u9488\u8c03\u7528\u5b9e\u9645\u5b50\u7c7b\u7684\u6210\u5458\u51fd\u6570\u3002\u8fd9\u79cd\u6280\u672f\u53ef\u4ee5\u8ba9\u7236\u7c7b\u7684\u6307\u9488\u6709\u201c\u591a\u79cd\u5f62\u6001\u201d\uff0c\u8fd9\u662f\u4e00\u79cd\u6cdb\u578b\u6280\u672f\u3002\u6240\u8c13\u6cdb\u578b\u6280\u672f\uff0c\u8bf4\u767d\u4e86\u5c31\u662f\u8bd5\u56fe\u4f7f\u7528\u4e0d\u53d8\u7684\u4ee3\u7801\u6765\u5b9e\u73b0\u53ef\u53d8\u7684\u7b97\u6cd5\u3002\u6bd4\u5982\uff1a\u6a21\u677f\u6280\u672f\uff0c<\/i>RTTI<i>\u6280\u672f\uff0c\u865a\u51fd\u6570\u6280\u672f\uff0c\u8981\u4e48\u662f\u8bd5\u56fe\u505a\u5230\u5728\u7f16\u8bd1\u65f6\u51b3\u8bae\uff0c\u8981\u4e48\u8bd5\u56fe\u505a\u5230\u8fd0\u884c\u65f6\u51b3\u8bae\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5173\u4e8e\u865a\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u6211\u5728\u8fd9\u91cc\u4e0d\u505a\u8fc7\u591a\u7684\u9610\u8ff0\u3002\u5927\u5bb6\u53ef\u4ee5\u770b\u770b\u76f8\u5173\u7684<\/i>C++<i>\u7684\u4e66\u7c4d\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u53ea\u60f3\u4ece\u865a\u51fd\u6570\u7684\u5b9e\u73b0\u673a\u5236\u4e0a\u9762\u4e3a\u5927\u5bb6<\/i><i>\u00a0<\/i><i>\u4e00\u4e2a\u6e05\u6670\u7684\u5256\u6790\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5f53\u7136\uff0c\u76f8\u540c\u7684\u6587\u7ae0\u5728\u7f51\u4e0a\u4e5f\u51fa\u73b0\u8fc7\u4e00\u4e9b\u4e86\uff0c\u4f46\u6211\u603b\u611f\u89c9\u8fd9\u4e9b\u6587\u7ae0\u4e0d\u662f\u5f88\u5bb9\u6613\u9605\u8bfb\uff0c\u5927\u6bb5\u5927\u6bb5\u7684\u4ee3\u7801\uff0c\u6ca1\u6709\u56fe\u7247\uff0c\u6ca1\u6709\u8be6\u7ec6\u7684\u8bf4\u660e\uff0c\u6ca1\u6709\u6bd4\u8f83\uff0c\u6ca1\u6709\u4e3e\u4e00\u53cd\u4e09\u3002\u4e0d\u5229\u4e8e\u5b66\u4e60\u548c\u9605\u8bfb\uff0c\u6240\u4ee5\u8fd9\u662f\u6211\u60f3\u5199\u4e0b\u8fd9\u7bc7\u6587\u7ae0\u7684\u539f\u56e0\u3002\u4e5f\u5e0c\u671b\u5927\u5bb6\u591a\u7ed9\u6211\u63d0\u610f\u89c1\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u8a00\u5f52\u6b63\u4f20\uff0c\u8ba9\u6211\u4eec\u4e00\u8d77\u8fdb\u5165\u865a\u51fd\u6570\u7684\u4e16\u754c\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<h1><i>\u865a\u51fd\u6570\u8868<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5bf9<\/i>C++\u00a0<i>\u4e86\u89e3\u7684\u4eba\u90fd\u5e94\u8be5\u77e5\u9053\u865a\u51fd\u6570\uff08<\/i>Virtual Function<i>\uff09\u662f\u901a\u8fc7\u4e00\u5f20\u865a\u51fd\u6570\u8868\uff08<\/i>Virtual Table<i>\uff09\u6765\u5b9e\u73b0\u7684\u3002\u7b80\u79f0\u4e3a<\/i>V-Table<i>\u3002\u5728\u8fd9\u4e2a\u8868\u4e2d\uff0c\u4e3b\u662f\u8981\u4e00\u4e2a\u7c7b\u7684\u865a\u51fd\u6570\u7684\u5730\u5740\u8868\uff0c\u8fd9\u5f20\u8868\u89e3\u51b3\u4e86\u7ee7\u627f\u3001\u8986\u76d6\u7684\u95ee\u9898\uff0c\u4fdd\u8bc1\u5176\u5bb9\u771f\u5b9e\u53cd\u5e94\u5b9e\u9645\u7684\u51fd\u6570\u3002\u8fd9\u6837\uff0c\u5728\u6709\u865a\u51fd\u6570\u7684\u7c7b\u7684\u5b9e\u4f8b\u4e2d\u8fd9\u4e2a\u8868\u88ab\u5206\u914d\u5728\u4e86\u8fd9\u4e2a\u5b9e\u4f8b\u7684\u5185\u5b58\u4e2d\uff0c\u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u7528\u7236\u7c7b\u7684\u6307\u9488\u6765\u64cd\u4f5c\u4e00\u4e2a\u5b50\u7c7b\u7684\u65f6\u5019\uff0c\u8fd9\u5f20\u865a\u51fd\u6570\u8868\u5c31\u663e\u5f97\u7531\u4e3a\u91cd\u8981\u4e86\uff0c\u5b83\u5c31\u50cf\u4e00\u4e2a\u5730\u56fe\u4e00\u6837\uff0c\u6307\u660e\u4e86\u5b9e\u9645\u6240\u5e94\u8be5\u8c03\u7528\u7684\u51fd\u6570\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u8fd9\u91cc\u6211\u4eec\u7740\u91cd\u770b\u4e00\u4e0b\u8fd9\u5f20\u865a\u51fd\u6570\u8868\u3002<\/i>C++<i>\u7684\u7f16\u8bd1\u5668\u5e94\u8be5\u662f\u4fdd\u8bc1\u865a\u51fd\u6570\u8868\u7684\u6307\u9488\u5b58\u5728\u4e8e\u5bf9\u8c61\u5b9e\u4f8b\u4e2d\u6700\u524d\u9762\u7684\u4f4d\u7f6e\uff08\u8fd9\u662f\u4e3a\u4e86\u4fdd\u8bc1\u53d6\u5230\u865a\u51fd\u6570\u8868\u7684\u6709\u6700\u9ad8\u7684\u6027\u80fd\u2014\u2014\u5982\u679c\u6709\u591a\u5c42\u7ee7\u627f\u6216\u662f\u591a\u91cd\u7ee7\u627f\u7684\u60c5\u51b5\u4e0b\uff09\u3002<\/i><i>\u00a0<\/i><i>\u8fd9\u610f\u5473\u7740\u6211\u4eec\u901a\u8fc7\u5bf9\u8c61\u5b9e\u4f8b\u7684\u5730\u5740\u5f97\u5230\u8fd9\u5f20\u865a\u51fd\u6570\u8868\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u904d\u5386\u5176\u4e2d\u51fd\u6570\u6307\u9488\uff0c\u5e76\u8c03\u7528\u76f8\u5e94\u7684\u51fd\u6570\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u542c\u6211\u626f\u4e86\u90a3\u4e48\u591a\uff0c\u6211\u53ef\u4ee5\u611f\u89c9\u51fa\u6765\u4f60\u73b0\u5728\u53ef\u80fd\u6bd4\u4ee5\u524d\u66f4\u52a0\u6655\u5934\u8f6c\u5411\u4e86\u3002<\/i><i>\u00a0<\/i><i>\u6ca1\u5173\u7cfb\uff0c\u4e0b\u9762\u5c31\u662f\u5b9e\u9645\u7684\u4f8b\u5b50\uff0c\u76f8\u4fe1\u806a\u660e\u7684\u4f60\u4e00\u770b\u5c31\u660e\u767d\u4e86\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5047\u8bbe\u6211\u4eec\u6709\u8fd9\u6837\u7684\u4e00\u4e2a\u7c7b\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">class\u00a0Base {<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0public:<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0f() { cout &lt;&lt;\u00a0&#8220;Base::f&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0g() { cout &lt;&lt;\u00a0&#8220;Base::g&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0h() { cout &lt;&lt;\u00a0&#8220;Base::h&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">};<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6309\u7167\u4e0a\u9762\u7684\u8bf4\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<\/i>Base<i>\u7684\u5b9e\u4f8b\u6765\u5f97\u5230\u865a\u51fd\u6570\u8868\u3002<\/i><i>\u00a0<\/i><i>\u4e0b\u9762\u662f\u5b9e\u9645\u4f8b\u7a0b\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0typedef\u00a0void(*Fun)(void);<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Base b;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Fun pFun = NULL;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cout &lt;&lt;\u00a0&#8220;<i>\u865a\u51fd\u6570\u8868\u5730\u5740\uff1a<\/i>&#8221;\u00a0&lt;&lt; (int*)(&amp;b) &lt;&lt; endl;<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cout &lt;&lt;\u00a0&#8220;<i>\u865a\u51fd\u6570\u8868<\/i>\u00a0\u2014\u00a0<i>\u7b2c\u4e00\u4e2a\u51fd\u6570\u5730\u5740\uff1a<\/i>&#8221;\u00a0&lt;&lt; (int*)*(int*)(&amp;b) &lt;&lt; endl;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Invoke the first virtual function<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)*((int*)*(int*)(&amp;b));<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5b9e\u9645\u8fd0\u884c\u7ecf\u679c\u5982\u4e0b\uff1a<\/i>(Windows XP+VS2003,\u00a0\u00a0Linux 2.6.22 + GCC 4.1.3)<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u865a\u51fd\u6570\u8868\u5730\u5740\uff1a<\/i>0012FED4<\/p>\n<p style=\"font-weight: 400;\"><i>\u865a\u51fd\u6570\u8868<\/i>\u00a0\u2014\u00a0<i>\u7b2c\u4e00\u4e2a\u51fd\u6570\u5730\u5740\uff1a<\/i>0044F148<\/p>\n<p style=\"font-weight: 400;\">Base::f<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5f3a\u884c\u628a<\/i>&amp;b<i>\u8f6c\u6210<\/i>int *<i>\uff0c\u53d6\u5f97\u865a\u51fd\u6570\u8868\u7684\u5730\u5740\uff0c\u7136\u540e\uff0c\u518d\u6b21\u53d6\u5740\u5c31\u53ef\u4ee5\u5f97\u5230\u7b2c\u4e00\u4e2a\u865a\u51fd\u6570\u7684\u5730\u5740\u4e86\uff0c\u4e5f\u5c31\u662f<\/i>Base::f()<i>\uff0c\u8fd9\u5728\u4e0a\u9762\u7684\u7a0b\u5e8f\u4e2d\u5f97\u5230\u4e86\u9a8c\u8bc1\uff08\u628a<\/i>int*\u00a0<i>\u5f3a\u5236\u8f6c\u6210\u4e86\u51fd\u6570\u6307\u9488\uff09\u3002\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u77e5\u9053\u5982\u679c\u8981\u8c03\u7528<\/i>Base::g()<i>\u548c<\/i>Base::h()<i>\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(Fun)*((int*)*(int*)(&amp;b)+0);\u00a0\u00a0\/\/ Base::f()<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(Fun)*((int*)*(int*)(&amp;b)+1);\u00a0\u00a0\/\/ Base::g()<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(Fun)*((int*)*(int*)(&amp;b)+2);\u00a0\u00a0\/\/ Base::h()<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u8fd9\u4e2a\u65f6\u5019\u4f60\u5e94\u8be5\u61c2\u4e86\u5427\u3002\u4ec0\u4e48\uff1f\u8fd8\u662f\u6709\u70b9\u6655\u3002\u4e5f\u662f\uff0c\u8fd9\u6837\u7684\u4ee3\u7801\u770b\u7740\u592a\u4e71\u4e86\u3002\u6ca1\u95ee\u9898\uff0c\u8ba9\u6211\u753b\u4e2a\u56fe\u89e3\u91ca\u4e00\u4e0b\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">&lt;?xml:namespace prefix = v \/&gt;<\/p>\n<p style=\"font-weight: 400;\"><i>\u6ce8\u610f\uff1a\u5728\u4e0a\u9762\u8fd9\u4e2a\u56fe\u4e2d\uff0c\u6211\u5728\u865a\u51fd\u6570\u8868\u7684\u6700\u540e\u591a\u52a0\u4e86\u4e00\u4e2a\u7ed3\u70b9\uff0c\u8fd9\u662f\u865a\u51fd\u6570\u8868\u7684\u7ed3\u675f\u7ed3\u70b9\uff0c\u5c31\u50cf\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\u7b26\u201c<\/i>\/0<i>\u201d\u4e00\u6837\uff0c\u5176\u6807\u5fd7\u4e86\u865a\u51fd\u6570\u8868\u7684\u7ed3\u675f\u3002\u8fd9\u4e2a\u7ed3\u675f\u6807\u5fd7\u7684\u503c\u5728\u4e0d\u540c\u7684\u7f16\u8bd1\u5668\u4e0b\u662f\u4e0d\u540c\u7684\u3002\u5728<\/i>WinXP+VS2003<i>\u4e0b\uff0c\u8fd9\u4e2a\u503c\u662f<\/i>NULL<i>\u3002\u800c\u5728<\/i>Ubuntu 7.10 + Linux 2.6.22 + GCC 4.1.3<i>\u4e0b\uff0c\u8fd9\u4e2a\u503c\u662f\u5982\u679c<\/i>1<i>\uff0c\u8868\u793a\u8fd8\u6709\u4e0b\u4e00\u4e2a\u865a\u51fd\u6570\u8868\uff0c\u5982\u679c\u503c\u662f<\/i>0<i>\uff0c\u8868\u793a\u662f\u6700\u540e\u4e00\u4e2a\u865a\u51fd\u6570\u8868\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4e0b\u9762\uff0c\u6211\u5c06\u5206\u522b\u8bf4\u660e\u201c\u65e0\u8986\u76d6\u201d\u548c\u201c\u6709\u8986\u76d6\u201d\u65f6\u7684\u865a\u51fd\u6570\u8868\u7684\u6837\u5b50\u3002\u6ca1\u6709\u8986\u76d6\u7236\u7c7b\u7684\u865a\u51fd\u6570\u662f\u6beb\u65e0\u610f\u4e49\u7684\u3002\u6211\u4e4b\u6240\u4ee5\u8981\u8bb2\u8ff0\u6ca1\u6709\u8986\u76d6\u7684\u60c5\u51b5\uff0c\u4e3b\u8981\u76ee\u7684\u662f\u4e3a\u4e86\u7ed9\u4e00\u4e2a\u5bf9\u6bd4\u3002\u5728\u6bd4\u8f83\u4e4b\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u52a0\u6e05\u695a\u5730\u77e5\u9053\u5176\u5185\u90e8\u7684\u5177\u4f53\u5b9e\u73b0\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<h1><i>\u4e00\u822c\u7ee7\u627f\uff08\u65e0\u865a\u51fd\u6570\u8986\u76d6\uff09<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4e0b\u9762\uff0c\u518d\u8ba9\u6211\u4eec\u6765\u770b\u770b\u7ee7\u627f\u65f6\u7684\u865a\u51fd\u6570\u8868\u662f\u4ec0\u4e48\u6837\u7684\u3002\u5047\u8bbe\u6709\u5982\u4e0b\u6240\u793a\u7684\u4e00\u4e2a\u7ee7\u627f\u5173\u7cfb\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u8bf7\u6ce8\u610f\uff0c\u5728\u8fd9\u4e2a\u7ee7\u627f\u5173\u7cfb\u4e2d\uff0c\u5b50\u7c7b\u6ca1\u6709\u91cd\u8f7d\u4efb\u4f55\u7236\u7c7b\u7684\u51fd\u6570\u3002\u90a3\u4e48\uff0c\u5728\u6d3e\u751f\u7c7b\u7684\u5b9e\u4f8b\u4e2d\uff0c\u5176\u865a\u51fd\u6570\u8868\u5982\u4e0b\u6240\u793a\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5bf9\u4e8e\u5b9e\u4f8b\uff1a<\/i>Derive d;\u00a0<i>\u7684\u865a\u51fd\u6570\u8868\u5982\u4e0b\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4e0b\u9762\u51e0\u70b9\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">1\uff09<i>\u865a\u51fd\u6570\u6309\u7167\u5176\u58f0\u660e\u987a\u5e8f\u653e\u4e8e\u8868\u4e2d\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">2\uff09<i>\u7236\u7c7b\u7684\u865a\u51fd\u6570\u5728\u5b50\u7c7b\u7684\u865a\u51fd\u6570\u524d\u9762\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6211\u76f8\u4fe1\u806a\u660e\u7684\u4f60\u4e00\u5b9a\u53ef\u4ee5\u53c2\u8003\u524d\u9762\u7684\u90a3\u4e2a\u7a0b\u5e8f\uff0c\u6765\u7f16\u5199\u4e00\u6bb5\u7a0b\u5e8f\u6765\u9a8c\u8bc1\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<h1><i>\u4e00\u822c\u7ee7\u627f\uff08\u6709\u865a\u51fd\u6570\u8986\u76d6\uff09<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u8986\u76d6\u7236\u7c7b\u7684\u865a\u51fd\u6570\u662f\u5f88\u663e\u7136\u7684\u4e8b\u60c5\uff0c\u4e0d\u7136\uff0c\u865a\u51fd\u6570\u5c31\u53d8\u5f97\u6beb\u65e0\u610f\u4e49\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\uff0c\u5982\u679c\u5b50\u7c7b\u4e2d\u6709\u865a\u51fd\u6570\u91cd\u8f7d\u4e86\u7236\u7c7b\u7684\u865a\u51fd\u6570\uff0c\u4f1a\u662f\u4e00\u4e2a\u4ec0\u4e48\u6837\u5b50\uff1f\u5047\u8bbe\uff0c\u6211\u4eec\u6709\u4e0b\u9762\u8fd9\u6837\u7684\u4e00\u4e2a\u7ee7\u627f\u5173\u7cfb\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4e3a\u4e86\u8ba9\u5927\u5bb6\u770b\u5230\u88ab\u7ee7\u627f\u8fc7\u540e\u7684\u6548\u679c\uff0c\u5728\u8fd9\u4e2a\u7c7b\u7684\u8bbe\u8ba1\u4e2d\uff0c\u6211\u53ea\u8986\u76d6\u4e86\u7236\u7c7b\u7684\u4e00\u4e2a\u51fd\u6570\uff1a<\/i>f()<i>\u3002\u90a3\u4e48\uff0c\u5bf9\u4e8e\u6d3e\u751f\u7c7b\u7684\u5b9e\u4f8b\uff0c\u5176\u865a\u51fd\u6570\u8868\u4f1a\u662f\u4e0b\u9762\u7684\u4e00\u4e2a\u6837\u5b50\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6211\u4eec\u4ece\u8868\u4e2d\u53ef\u4ee5\u770b\u5230\u4e0b\u9762\u51e0\u70b9\uff0c<\/i><\/p>\n<p style=\"font-weight: 400;\">1\uff09<i>\u8986\u76d6\u7684<\/i>f()<i>\u51fd\u6570\u88ab\u653e\u5230\u4e86\u865a\u8868\u4e2d\u539f\u6765\u7236\u7c7b\u865a\u51fd\u6570\u7684\u4f4d\u7f6e\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">2\uff09<i>\u6ca1\u6709\u88ab\u8986\u76d6\u7684\u51fd\u6570\u4f9d\u65e7\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u770b\u5230\u5bf9\u4e8e\u4e0b\u9762\u8fd9\u6837\u7684\u7a0b\u5e8f\uff0c<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Base *b =\u00a0new\u00a0Derive();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b-&gt;f();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u7531<\/i>b<i>\u6240\u6307\u7684\u5185\u5b58\u4e2d\u7684\u865a\u51fd\u6570\u8868\u7684<\/i>f()<i>\u7684\u4f4d\u7f6e\u5df2\u7ecf\u88ab<\/i>Derive::f()<i>\u51fd\u6570\u5730\u5740\u6240\u53d6\u4ee3\uff0c\u4e8e\u662f\u5728\u5b9e\u9645\u8c03\u7528\u53d1\u751f\u65f6\uff0c\u662f<\/i>Derive::f()<i>\u88ab\u8c03\u7528\u4e86\u3002\u8fd9\u5c31\u5b9e\u73b0\u4e86\u591a\u6001\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<h1><i>\u591a\u91cd\u7ee7\u627f\uff08\u65e0\u865a\u51fd\u6570\u8986\u76d6\uff09<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4e0b\u9762\uff0c\u518d\u8ba9\u6211\u4eec\u6765\u770b\u770b\u591a\u91cd\u7ee7\u627f\u4e2d\u7684\u60c5\u51b5\uff0c\u5047\u8bbe\u6709\u4e0b\u9762\u8fd9\u6837\u4e00\u4e2a\u7c7b\u7684\u7ee7\u627f\u5173\u7cfb\u3002\u6ce8\u610f\uff1a\u5b50\u7c7b\u5e76\u6ca1\u6709\u8986\u76d6\u7236\u7c7b\u7684\u51fd\u6570\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5bf9\u4e8e\u5b50\u7c7b\u5b9e\u4f8b\u4e2d\u7684\u865a\u51fd\u6570\u8868\uff0c\u662f\u4e0b\u9762\u8fd9\u4e2a\u6837\u5b50\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">1\uff09\u00a0\u00a0<i>\u6bcf\u4e2a\u7236\u7c7b\u90fd\u6709\u81ea\u5df1\u7684\u865a\u8868\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">2\uff09\u00a0\u00a0<i>\u5b50\u7c7b\u7684\u6210\u5458\u51fd\u6570\u88ab\u653e\u5230\u4e86\u7b2c\u4e00\u4e2a\u7236\u7c7b\u7684\u8868\u4e2d\u3002\uff08\u6240\u8c13\u7684\u7b2c\u4e00\u4e2a\u7236\u7c7b\u662f\u6309\u7167\u58f0\u660e\u987a\u5e8f\u6765\u5224\u65ad\u7684\uff09<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u8fd9\u6837\u505a\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u4e0d\u540c\u7684\u7236\u7c7b\u7c7b\u578b\u7684\u6307\u9488\u6307\u5411\u540c\u4e00\u4e2a\u5b50\u7c7b\u5b9e\u4f8b\uff0c\u800c\u80fd\u591f\u8c03\u7528\u5230\u5b9e\u9645\u7684\u51fd\u6570\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<h1><i>\u591a\u91cd\u7ee7\u627f\uff08\u6709\u865a\u51fd\u6570\u8986\u76d6\uff09<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4e0b\u9762\u6211\u4eec\u518d\u6765\u770b\u770b\uff0c\u5982\u679c\u53d1\u751f\u865a\u51fd\u6570\u8986\u76d6\u7684\u60c5\u51b5\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4e0b\u56fe\u4e2d\uff0c\u6211\u4eec\u5728\u5b50\u7c7b\u4e2d\u8986\u76d6\u4e86\u7236\u7c7b\u7684<\/i>f()<i>\u51fd\u6570\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4e0b\u9762\u662f\u5bf9\u4e8e\u5b50\u7c7b\u5b9e\u4f8b\u4e2d\u7684\u865a\u51fd\u6570\u8868\u7684\u56fe\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6211\u4eec\u53ef\u4ee5\u770b\u89c1\uff0c\u4e09\u4e2a\u7236\u7c7b\u865a\u51fd\u6570\u8868\u4e2d\u7684<\/i>f()<i>\u7684\u4f4d\u7f6e\u88ab\u66ff\u6362\u6210\u4e86\u5b50\u7c7b\u7684\u51fd\u6570\u6307\u9488\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4efb\u4e00\u9759\u6001\u7c7b\u578b\u7684\u7236\u7c7b\u6765\u6307\u5411\u5b50\u7c7b\uff0c\u5e76\u8c03\u7528\u5b50\u7c7b\u7684<\/i>f()<i>\u4e86\u3002\u5982\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Derive d;<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Base1 *b1 = &amp;d;<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Base2 *b2 = &amp;d;<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Base3 *b3 = &amp;d;<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b1-&gt;f();\u00a0\/\/Derive::f()<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b2-&gt;f();\u00a0\/\/Derive::f()<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b3-&gt;f();\u00a0\/\/Derive::f()<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b1-&gt;g();\u00a0\/\/Base1::g()<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b2-&gt;g();\u00a0\/\/Base2::g()<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b3-&gt;g();\u00a0\/\/Base3::g()<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<h1><i>\u5b89\u5168\u6027<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6bcf\u6b21\u5199<\/i>C++<i>\u7684\u6587\u7ae0\uff0c\u603b\u514d\u4e0d\u4e86\u8981\u6279\u5224\u4e00\u4e0b<\/i>C++<i>\u3002\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u4e0d\u4f8b\u5916\u3002\u901a\u8fc7\u4e0a\u9762\u7684\u8bb2\u8ff0\uff0c\u76f8\u4fe1\u6211\u4eec\u5bf9\u865a\u51fd\u6570\u8868\u6709\u4e00\u4e2a\u6bd4\u8f83\u7ec6\u81f4\u7684\u4e86\u89e3\u4e86\u3002\u6c34\u53ef\u8f7d\u821f\uff0c\u4ea6\u53ef\u8986\u821f\u3002\u4e0b\u9762\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u770b\u6211\u4eec\u53ef\u4ee5\u7528\u865a\u51fd\u6570\u8868\u6765\u5e72\u70b9\u4ec0\u4e48\u574f\u4e8b\u5427\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><b><strong><i>\u4e00\u3001\u901a\u8fc7\u7236\u7c7b\u578b\u7684\u6307\u9488\u8bbf\u95ee\u5b50\u7c7b\u81ea\u5df1\u7684\u865a\u51fd\u6570<\/i><\/strong><\/b><\/p>\n<p style=\"font-weight: 400;\"><i>\u6211\u4eec\u77e5\u9053\uff0c\u5b50\u7c7b\u6ca1\u6709\u91cd\u8f7d\u7236\u7c7b\u7684\u865a\u51fd\u6570\u662f\u4e00\u4ef6\u6beb\u65e0\u610f\u4e49\u7684\u4e8b\u60c5\u3002\u56e0\u4e3a\u591a\u6001\u4e5f\u662f\u8981\u57fa\u4e8e\u51fd\u6570\u91cd\u8f7d\u7684\u3002\u867d\u7136\u5728\u4e0a\u9762\u7684\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230<\/i>Base1<i>\u7684\u865a\u8868\u4e2d\u6709<\/i>Derive<i>\u7684\u865a\u51fd\u6570\uff0c\u4f46\u6211\u4eec\u6839\u672c\u4e0d\u53ef\u80fd\u4f7f\u7528\u4e0b\u9762\u7684\u8bed\u53e5\u6765\u8c03\u7528\u5b50\u7c7b\u7684\u81ea\u6709\u865a\u51fd\u6570\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Base1 *b1 =\u00a0new\u00a0Derive();<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b1-&gt;f1();\u00a0\u00a0\/\/<i>\u7f16\u8bd1\u51fa\u9519<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u4efb\u4f55\u5984\u56fe\u4f7f\u7528\u7236\u7c7b\u6307\u9488\u60f3\u8c03\u7528\u5b50\u7c7b\u4e2d\u7684<b><strong>\u672a\u8986\u76d6\u7236\u7c7b\u7684\u6210\u5458\u51fd\u6570<\/strong><\/b>\u7684\u884c\u4e3a\u90fd\u4f1a\u88ab\u7f16\u8bd1\u5668\u89c6\u4e3a\u975e\u6cd5\uff0c\u6240\u4ee5\uff0c\u8fd9\u6837\u7684\u7a0b\u5e8f\u6839\u672c\u65e0\u6cd5\u7f16\u8bd1\u901a\u8fc7\u3002\u4f46\u5728\u8fd0\u884c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6307\u9488\u7684\u65b9\u5f0f\u8bbf\u95ee\u865a\u51fd\u6570\u8868\u6765\u8fbe\u5230\u8fdd\u53cd<\/i>C++<i>\u8bed\u4e49\u7684\u884c\u4e3a\u3002\uff08\u5173\u4e8e\u8fd9\u65b9\u9762\u7684\u5c1d\u8bd5\uff0c\u901a\u8fc7\u9605\u8bfb\u540e\u9762\u9644\u5f55\u7684\u4ee3\u7801\uff0c\u76f8\u4fe1\u4f60\u53ef\u4ee5\u505a\u5230\u8fd9\u4e00\u70b9\uff09<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><b><strong><i>\u4e8c\u3001\u8bbf\u95ee<\/i>non-public<\/strong><\/b><b><strong><i>\u7684\u865a\u51fd\u6570<\/i><\/strong><\/b><\/p>\n<p style=\"font-weight: 400;\"><i>\u53e6\u5916\uff0c\u5982\u679c\u7236\u7c7b\u7684\u865a\u51fd\u6570\u662f<\/i>private<i>\u6216\u662f<\/i>protected<i>\u7684\uff0c\u4f46\u8fd9\u4e9b\u975e<\/i>public<i>\u7684\u865a\u51fd\u6570\u540c\u6837\u4f1a\u5b58\u5728\u4e8e\u865a\u51fd\u6570\u8868\u4e2d\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u540c\u6837\u53ef\u4ee5\u4f7f\u7528\u8bbf\u95ee\u865a\u51fd\u6570\u8868\u7684\u65b9\u5f0f\u6765\u8bbf\u95ee\u8fd9\u4e9b<\/i>non-public<i>\u7684\u865a\u51fd\u6570\uff0c\u8fd9\u662f\u5f88\u5bb9\u6613\u505a\u5230\u7684\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5982\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">class\u00a0Base {<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0private:<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0f() { cout &lt;&lt;\u00a0&#8220;Base::f&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">};<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">class\u00a0Derive :\u00a0public\u00a0Base{<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">};<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">typedef\u00a0void(*Fun)(void);<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">void\u00a0main() {<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0Derive d;<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0Fun\u00a0\u00a0pFun = (Fun)*((int*)*(int*)(&amp;d)+0);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">}<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<h1><i>\u7ed3\u675f\u8bed<\/i><\/h1>\n<p style=\"font-weight: 400;\">C++<i>\u8fd9\u95e8\u8bed\u8a00\u662f\u4e00\u95e8<\/i>Magic<i>\u7684\u8bed\u8a00\uff0c\u5bf9\u4e8e\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0c\u6211\u4eec\u4f3c\u4e4e\u6c38\u8fdc\u6478\u4e0d\u6e05\u695a\u8fd9\u95e8\u8bed\u8a00\u80cc\u7740\u6211\u4eec\u5728\u5e72\u4e86\u4ec0\u4e48\u3002\u9700\u8981\u719f\u6089\u8fd9\u95e8\u8bed\u8a00\uff0c\u6211\u4eec\u5c31\u5fc5\u9700\u8981\u4e86\u89e3<\/i>C++<i>\u91cc\u9762\u7684\u90a3\u4e9b\u4e1c\u897f\uff0c\u9700\u8981\u53bb\u4e86\u89e3<\/i>C++<i>\u4e2d\u90a3\u4e9b\u5371\u9669\u7684\u4e1c\u897f\u3002\u4e0d\u7136\uff0c\u8fd9\u662f\u4e00\u79cd\u642c\u8d77\u77f3\u5934\u7838\u81ea\u5df1\u811a\u7684\u7f16\u7a0b\u8bed\u8a00\u3002<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u5728\u6587\u7ae0\u675f\u4e4b\u524d\u8fd8\u662f\u4ecb\u7ecd\u4e00\u4e0b\u81ea\u5df1\u5427\u3002\u6211\u4ece\u4e8b\u8f6f\u4ef6\u7814\u53d1\u6709\u5341\u4e2a\u5e74\u5934\u4e86\uff0c\u76ee\u524d\u662f\u8f6f\u4ef6\u5f00\u53d1\u6280\u672f\u4e3b\u7ba1\uff0c\u6280\u672f\u65b9\u9762\uff0c\u4e3b\u653b<\/i>Unix\/C\/C++<i>\uff0c\u6bd4\u8f83\u559c\u6b22\u7f51\u7edc\u4e0a\u7684\u6280\u672f\uff0c\u6bd4\u5982\u5206\u5e03\u5f0f\u8ba1\u7b97\uff0c\u7f51\u683c\u8ba1\u7b97\uff0c<\/i>P2P<i>\uff0c<\/i>Ajax<i>\u7b49\u4e00\u5207\u548c\u4e92\u8054\u7f51\u76f8\u5173\u7684\u4e1c\u897f\u3002\u7ba1\u7406\u65b9\u9762\u6bd4\u8f83\u64c5\u957f\u4e8e\u56e2\u961f\u5efa\u8bbe\uff0c\u6280\u672f\u8d8b\u52bf\u5206\u6790\uff0c\u9879\u76ee\u7ba1\u7406\u3002\u6b22\u8fce\u5927\u5bb6\u548c\u6211\u4ea4\u6d41\uff0c\u6211\u7684<\/i>MSN<i>\u548c<\/i>Email<i>\u662f\uff1a<\/i><a href=\"mailto:haoel@hotmail.com\">haoel@hotmail.com<\/a><\/p>\n<p style=\"font-weight: 400;\">\n<h1><i>\u9644\u5f55\u4e00\uff1a<\/i>VC<i>\u4e2d\u67e5\u770b\u865a\u51fd\u6570\u8868<\/i><\/h1>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u6211\u4eec\u53ef\u4ee5\u5728<\/i>VC<i>\u7684<\/i>IDE<i>\u73af\u5883\u4e2d\u7684<\/i>Debug<i>\u72b6\u6001\u4e0b\u5c55\u5f00\u7c7b\u7684\u5b9e\u4f8b\u5c31\u53ef\u4ee5\u770b\u5230\u865a\u51fd\u6570\u8868\u4e86\uff08\u5e76\u4e0d\u662f\u5f88\u5b8c\u6574\u7684\uff09<\/i><\/p>\n<h1><i>\u9644\u5f55<\/i><i>\u00a0<\/i><i>\u4e8c\uff1a\u4f8b\u7a0b<\/i><\/h1>\n<p style=\"font-weight: 400;\"><i>\u4e0b\u9762\u662f\u4e00\u4e2a\u5173\u4e8e\u591a\u91cd\u7ee7\u627f\u7684\u865a\u51fd\u6570\u8868\u8bbf\u95ee\u7684\u4f8b\u7a0b\uff1a<\/i><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">#include\u00a0&lt;iostream&gt;<\/p>\n<p style=\"font-weight: 400;\">using\u00a0namespace\u00a0std;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">class\u00a0Base1 {<\/p>\n<p style=\"font-weight: 400;\">public:<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0f() { cout &lt;&lt;\u00a0&#8220;Base1::f&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0g() { cout &lt;&lt;\u00a0&#8220;Base1::g&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0h() { cout &lt;&lt;\u00a0&#8220;Base1::h&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">};<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">class\u00a0Base2 {<\/p>\n<p style=\"font-weight: 400;\">public:<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0f() { cout &lt;&lt;\u00a0&#8220;Base2::f&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0g() { cout &lt;&lt;\u00a0&#8220;Base2::g&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0h() { cout &lt;&lt;\u00a0&#8220;Base2::h&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">};<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">class\u00a0Base3 {<\/p>\n<p style=\"font-weight: 400;\">public:<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0f() { cout &lt;&lt;\u00a0&#8220;Base3::f&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0g() { cout &lt;&lt;\u00a0&#8220;Base3::g&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0h() { cout &lt;&lt;\u00a0&#8220;Base3::h&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">};<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">class\u00a0Derive :\u00a0public\u00a0Base1,\u00a0public\u00a0Base2,\u00a0public\u00a0Base3 {<\/p>\n<p style=\"font-weight: 400;\">public:<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0f() { cout &lt;&lt;\u00a0&#8220;Derive::f&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0virtual\u00a0void\u00a0g1() { cout &lt;&lt;\u00a0&#8220;Derive::g1&#8221;\u00a0&lt;&lt; endl; }<\/p>\n<p style=\"font-weight: 400;\">};<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">typedef\u00a0void(*Fun)(void);<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">int\u00a0main()<\/p>\n<p style=\"font-weight: 400;\">{<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Fun pFun = NULL;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Derive d;<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int** pVtab = (int**)&amp;d;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<b><strong>\/\/Base1&#8217;s vtable<\/strong><\/b><\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+0)+0);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[0][0];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+0)+1);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[0][1];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+0)+2);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[0][2];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Derive&#8217;s vtable<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+0)+3);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[0][3];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/The tail of the vtable<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[0][4];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cout&lt;&lt;pFun&lt;&lt;endl;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<b><strong>\/\/Base2&#8217;s vtable<\/strong><\/b><\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+1)+0);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[1][0];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+1)+1);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[1][1];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[1][2];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/The tail of the vtable<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[1][3];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cout&lt;&lt;pFun&lt;&lt;endl;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<b><strong>\/\/Base3&#8217;s vtable<\/strong><\/b><\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+1)+0);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[2][0];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/pFun = (Fun)*((int*)*(int*)((int*)&amp;d+1)+1);<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[2][1];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[2][2];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun();<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/The tail of the vtable<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pFun = (Fun)pVtab[2][3];<\/p>\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cout&lt;&lt;pFun&lt;&lt;endl;<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return\u00a00;<\/p>\n<p style=\"font-weight: 400;\">}<\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><b><strong>(<\/strong><\/b><b><strong><i>\u8f6c\u8f7d\u65f6\u8bf7\u6ce8\u660e\u4f5c\u8005\u548c\u51fa\u5904\u3002\u672a\u7ecf\u8bb8\u53ef\uff0c\u8bf7\u52ff\u7528\u4e8e\u5546\u4e1a\u7528\u9014<\/i>)<\/strong><\/b><\/p>\n<p style=\"font-weight: 400;\">\n<p style=\"font-weight: 400;\"><i>\u66f4\u591a\u6587\u7ae0\u8bf7\u8bbf\u95ee\u6211\u7684<\/i>Blog:\u00a0<a href=\"http:\/\/blog.csdn.net\/haoel\">http:\/\/blog.csdn.net\/haoel<\/a><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9648\u7693 http:\/\/blog.csdn.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[24],"tags":[121],"class_list":["post-1474","post","type-post","status-publish","format-standard","hentry","category-value_docs","tag-05-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=1474"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1474\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=1474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=1474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=1474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}