{"id":44,"date":"2023-02-07T16:00:44","date_gmt":"2023-02-07T08:00:44","guid":{"rendered":"http:\/\/zkxx.xyz\/?p=44"},"modified":"2023-02-07T16:01:21","modified_gmt":"2023-02-07T08:01:21","slug":"c%e7%9a%84%e6%97%a9%e7%bb%91%e5%ae%9a%e5%92%8c%e8%bf%9f%e7%bb%91%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/zkxx.xyz\/index.php\/2023\/02\/07\/c%e7%9a%84%e6%97%a9%e7%bb%91%e5%ae%9a%e5%92%8c%e8%bf%9f%e7%bb%91%e5%ae%9a\/","title":{"rendered":"c++\u7684\u65e9\u7ed1\u5b9a\u548c\u8fdf\u7ed1\u5b9a"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/zkxx.xyz\/wp-content\/uploads\/2023\/02\/image.png\" alt=\"\" class=\"wp-image-45\" width=\"186\" height=\"177\" srcset=\"https:\/\/zkxx.xyz\/wp-content\/uploads\/2023\/02\/image.png 346w, https:\/\/zkxx.xyz\/wp-content\/uploads\/2023\/02\/image-300x286.png 300w\" sizes=\"auto, (max-width: 186px) 100vw, 186px\" \/><figcaption class=\"wp-element-caption\">\u9020\u7269\u4e3b\u8bed\u8a00<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ec0\u4e48\u53eb\u7ed1\u5b9a<\/h3>\n\n\n\n<p>Connecting a function call to a function body is called binding.\uff08\u5c06\u51fd\u6570\u4f53\u548c\u51fd\u6570\u8c03\u7528\u5173\u8054\u8d77\u6765\uff0c\u5c31\u53eb\u7ed1\u5b9a\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ec0\u4e48\u662f\u65e9\u7ed1\u5b9a\uff1f\uff08Early binding\uff09<\/h2>\n\n\n\n<p>When binding is performed before the program is run (by the compiler and linker), it&#8217; s called early binding<br>\u5728\u7a0b\u5e8f\u8fd0\u884c\u4e4b\u524d\uff08\u5373\u5728\u7f16\u8bd1\u548c\u94fe\u63a5\u65f6\uff09\uff0c\u6267\u884c\u7684\u7ed1\u5b9a\u662f\u65e9\u7ed1\u5b9a\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u665a\u7ed1\u5b9a\uff1f\uff08Late binding\uff09<\/h2>\n\n\n\n<p>\u987e\u540d\u601d\u4e49\uff0clate binding, which means the binding occurs at runtime, based on the type of the object.&nbsp;When a language implements late binding, there must be some mechanism to determine the &nbsp;type of the object at runtime and call the appropriate member function.<br>\u8fdf\u7ed1\u5b9a\u53d1\u751f\u5728\u8fd0\u884c\u65f6\uff0c\u57fa\u4e8e\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u5f53\u4e00\u79cd\u8bed\u8a00\u5b9e\u73b0\u8fdf\u7ed1\u5b9a\u65f6\uff0c\u5fc5\u987b\u6709\u67d0\u79cd\u673a\u5236\u786e\u5b9a\u5bf9\u8c61\u7684\u5177\u4f53\u7c7b\u578b\u7136\u540e\u8c03\u7528\u5408\u9002\u7684\u6210\u5458\u51fd\u6570\u3002<\/p>\n\n\n\n<figure class=\"wp-block-pullquote\"><blockquote><p><strong><em>\u5f15\u7528\u4e00\u53e5Bruce Eckel\u7684\u8bdd\uff1a<\/em><\/strong><\/p><cite>\u201c<em>\u4e0d\u8981\u72af\u50bb\uff0c\u5982\u679c\u5b83\u4e0d\u662f\u665a\u90a6\u5b9a\uff0c\u5b83\u5c31\u4e0d\u662f\u591a\u6001\u3002<\/em>\u201d<\/cite><\/blockquote><\/figure>\n\n\n\n<p>\u5f88\u660e\u663e\uff0c\u8fdf\u7ed1\u5b9a\u5c31\u662f<strong>\u7528\u6765\u89e3\u51b3\u591a\u6001\u7279\u6027<\/strong>\u7684\u3002\u5728 C++ \u4e2d\uff0c\u5728\u57fa\u7c7b\u7684\u6210\u5458\u51fd\u6570\u58f0\u660e\u524d\u52a0\u4e0a\u5173\u952e\u5b57virtual\u5373\u53ef\u8ba9\u8be5\u51fd\u6570\u6210\u4e3a<strong>\u865a\u51fd\u6570<\/strong>\uff0c\u6d3e\u751f\u7c7b\u4e2d\u5bf9\u6b64\u51fd\u6570\u7684\u4e0d\u540c\u5b9e\u73b0\u90fd\u4f1a\u7ee7\u627f\u8fd9\u4e00\u4fee\u9970\u7b26\uff0c\u5141\u8bb8\u540e\u7eed\u6d3e\u751f\u7c7b\u8986\u76d6\uff0c\u8fbe\u5230<strong>\u8fdf\u7ed1\u5b9a<\/strong>\u7684\u6548\u679c\u3002&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u793a\u4f8b\uff1a\nclass Animal\n{\npublic:\n\tvirtual void sleep()  \/\/\u865a\u51fd\u6570\n\t{\n\t\tcout &lt;&lt; \"Animal sleep!\" &lt;&lt; endl;\n\t}\n \n\tvoid breath()\n\t{\n\t\tcout &lt;&lt; \"Animal breath!\" &lt;&lt; endl;\n\tvoid sleep()   \/\/\u51fd\u6570\u91cd\u5199\uff0c\u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0virtual,\u4e5f\u53ef\u4ee5\u4e0d\u6dfb\u52a0\n\t{\n\t\tcout &lt;&lt; \"Fish sleep!\" &lt;&lt; endl;\n\t}\n\tvoid breath()\n\t{\n\t\tcout &lt;&lt; \"Fish breath!\" &lt;&lt; endl;\n\t}\n};\nint main()\n{\n\tFish f;\n\tAnimal* a = &amp;f; \/\/\u57fa\u7c7b\u6307\u9488\u6307\u5411\u6d3e\u751f\u7c7b\n\ta-&gt;breath();\n\ta-&gt;sleep();\n\treturn 0;\n}\n\/\/ \u7ed3\u679c\uff1a  Animal breath!\n           Fish sleep!<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u53eb\u7ed1\u5b9a Connecting a function call to a function body is  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":3,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":48,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/posts\/44\/revisions\/48"}],"wp:attachment":[{"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zkxx.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}