{"id":615,"date":"2023-12-29T09:01:01","date_gmt":"2023-12-29T01:01:01","guid":{"rendered":""},"modified":"2023-12-29T09:01:01","modified_gmt":"2023-12-29T01:01:01","slug":"C++\u4e2d\u91cd\u8f7d\u548c\u91cd\u5199\u7684\u533a\u522b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/615.html","title":{"rendered":"C++\u4e2d\u91cd\u8f7d\u548c\u91cd\u5199\u7684\u533a\u522b"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u91cd\u8f7d<\/h2>\n

\u662f\u6307\u540c\u4e00\u53ef\u8bbf\u95ee\u533a\u5185\u88ab\u58f0\u660e\u7684\u51e0\u4e2a\u5177\u6709\u4e0d\u540c\u53c2\u6570\u5217\uff08\u53c2\u6570\u7684\u7c7b\u578b\uff0c\u4e2a\u6570\uff0c\u987a\u5e8f\u4e0d\u540c\uff09\u7684\u540c\u540d\u51fd\u6570\uff0c\u6839\u636e\u53c2\u6570\u5217\u8868\u786e\u5b9a\u8c03\u7528\u54ea\u4e2a\u51fd\u6570\uff0c\u91cd\u8f7d\u4e0d\u5173\u5fc3\u51fd\u6570\u8fd4\u56de\u7c7b\u578b\u3002<\/p>\n

#include<\/span><bits\/stdc++.h><\/span><\/span>\n\nusing namespace std;<\/span>\n\nclass A\n{ \n   <\/span>\n\tvoid<\/span> fun<\/span>(<\/span>)<\/span> { \n   <\/span>}<\/span>;<\/span>\n\tvoid<\/span> fun<\/span>(<\/span>int<\/span> i)<\/span> { \n   <\/span>}<\/span>;<\/span>\n\tvoid<\/span> fun<\/span>(<\/span>int<\/span> i,<\/span> int<\/span> j)<\/span> { \n   <\/span>}<\/span>;<\/span>\n}<\/span>;<\/span>\n<\/code><\/pre>\n

\u91cd\u5199\uff08\u8986\u5199\uff09<\/h2>\n

\u662f\u6307\u6d3e\u751f\u7c7b\u4e2d\u5b58\u5728\u91cd\u65b0\u5b9a\u4e49\u7684\u51fd\u6570\u3002\u5176\u51fd\u6570\u540d\uff0c\u53c2\u6570\u5217\u8868\uff0c\u8fd4\u56de\u503c\u7c7b\u578b\uff0c\u6240\u6709\u90fd\u5fc5\u987b\u540c\u57fa\u7c7b\u4e2d\u88ab\u91cd\u5199\u7684\u51fd\u6570\u4e00\u81f4\u3002\u53ea\u6709\u51fd\u6570\u4f53\u4e0d\u540c\uff08\u82b1\u62ec\u53f7\u5185\uff09\uff0c\u6d3e\u751f\u7c7b\u8c03\u7528\u65f6\u4f1a\u8c03\u7528\u6d3e\u751f\u7c7b\u7684\u91cd\u5199\u51fd\u6570\uff0c\u4e0d\u4f1a\u8c03\u7528\u88ab\u91cd\u5199\u51fd\u6570\u3002\u91cd\u5199\u7684\u57fa\u7c7b\u4e2d\u88ab\u91cd\u5199\u7684\u51fd\u6570\u5fc5\u987b\u6709virtual\u4fee\u9970\u3002<\/p>\n

#include<\/span><bits\/stdc++.h><\/span><\/span>\n\nusing namespace std;<\/span>\n\nclass A\n{ \n   <\/span>\npublic:<\/span>\n\tvirtual\tvoid<\/span> fun<\/span>(<\/span>)<\/span>\n\t{ \n   <\/span>\n\t\tcout <<<\/span> \"A\"<\/span>;<\/span>\n\t}<\/span>\n}<\/span>;<\/span>\nclass B :<\/span>public A\n{ \n   <\/span>\npublic:<\/span>\n\tvirtual void<\/span> fun<\/span>(<\/span>)<\/span>\n\t{ \n   <\/span>\n\t\tcout <<<\/span> \"B\"<\/span>;<\/span>\n\t}<\/span>\n}<\/span>;<\/span>\nint<\/span> main<\/span>(<\/span>void<\/span>)<\/span>\n{ \n   <\/span>\n\tA*<\/span> a =<\/span> new B<\/span>(<\/span>)<\/span>;<\/span>\n\ta-><\/span>fun<\/span>(<\/span>)<\/span>;<\/span>\/\/\u8f93\u51faB<\/span>\n}<\/span>\n<\/code><\/pre>\n

\u91cd\u8f7d\u548c\u91cd\u5199\u7684\u533a\u522b<\/h2>\n

\uff081\uff09\u8303\u56f4\u533a\u522b\uff1a\u91cd\u5199\u548c\u88ab\u91cd\u5199\u7684\u51fd\u6570\u5728\u4e0d\u540c\u7684\u7c7b\u4e2d\uff0c\u91cd\u8f7d\u548c\u88ab\u91cd\u8f7d\u7684\u51fd\u6570\u5728\u540c\u4e00\u7c7b\u4e2d\u3002<\/p>\n

\uff082\uff09\u53c2\u6570\u533a\u522b\uff1a\u91cd\u5199\u4e0e\u88ab\u91cd\u5199\u7684\u51fd\u6570\u53c2\u6570\u5217\u8868\u4e00\u5b9a\u76f8\u540c\uff0c\u91cd\u8f7d\u548c\u88ab\u91cd\u8f7d\u7684\u51fd\u6570\u53c2\u6570\u5217\u8868\u4e00\u5b9a\u4e0d\u540c\u3002<\/p>\n

\uff083\uff09virtual\u7684\u533a\u522b\uff1a\u91cd\u5199\u7684\u57fa\u7c7b\u51fd\u6570\u5fc5\u987b\u8981\u6709virtual\u4fee\u9970\uff0c\u91cd\u8f7d\u51fd\u6570\u548c\u88ab\u91cd\u8f7d\u51fd\u6570\u53ef\u4ee5\u88abvirtual\u4fee\u9970\uff0c\u4e5f\u53ef\u4ee5\u6ca1\u6709\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"C++\u4e2d\u91cd\u8f7d\u548c\u91cd\u5199\u7684\u533a\u522b\u91cd\u8f7d\u662f\u6307\u540c\u4e00\u53ef\u8bbf\u95ee\u533a\u5185\u88ab\u58f0\u660e\u7684\u51e0\u4e2a\u5177\u6709\u4e0d\u540c\u53c2\u6570\u5217\uff08\u53c2\u6570\u7684\u7c7b\u578b\uff0c\u4e2a\u6570\uff0c\u987a\u5e8f\u4e0d\u540c\uff09\u7684\u540c\u540d\u51fd\u6570\uff0c\u6839\u636e\u53c2...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/615"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}