{"id":439,"date":"2011-03-03T16:14:31","date_gmt":"2011-03-03T23:14:31","guid":{"rendered":"http:\/\/www.cchsu.com\/arthur\/?p=439"},"modified":"2011-03-03T16:14:31","modified_gmt":"2011-03-03T23:14:31","slug":"%e8%ae%80%e6%9b%b8%e7%ad%86%e8%a8%98-inside-the-c-object-model-3","status":"publish","type":"post","link":"http:\/\/www.cchsu.com\/arthur\/2011\/03\/03\/439\/","title":{"rendered":"\u8b80\u66f8\u7b46\u8a18: Inside the C++ Object Model (3)"},"content":{"rendered":"<p>\u5e95\u4e0b\u7684\u5be6\u9a57\u8b49\u660e\u82e5 class \u5ba3\u544a\u6216\u7e7c\u627f virtual function \u6642\uff0c\u7de8\u8b6f\u5668\u6703\u81ea\u52d5\u751f\u6210 constructor<br \/>\n<span class=\"collapseomatic \" id=\"id6a1827a23488f\"  tabindex=\"0\" title=\"exp_def_ctor.h\"    >exp_def_ctor.h<\/span><div id=\"target-id6a1827a23488f\" class=\"collapseomatic_content \">\n<pre lang=\"cpp\" line=\"1\">\r\nclass CWidget\r\n{\r\npublic:\r\n    virtual void flip() const = 0;\r\n};\r\n\r\nclass CBell : public CWidget\r\n{\r\npublic:\r\n    virtual void flip() const;\r\n};\r\n\r\nclass CWhistle : public CWidget\r\n{\r\npublic:\r\n    virtual void flip() const;\r\n};\r\n<\/pre>\n<\/div>\n<span class=\"collapseomatic \" id=\"id6a1827a23497f\"  tabindex=\"0\" title=\"exp_def_ctor.cpp\"    >exp_def_ctor.cpp<\/span><div id=\"target-id6a1827a23497f\" class=\"collapseomatic_content \">\n<pre lang=\"cpp\" line=\"1\">\r\n#include \"exp_def_ctor.h\"\r\n#include <iostream>\r\nusing namespace std;\r\n\r\nvoid CBell::flip() const { cout << \"bell\" << endl; }\r\nvoid CWhistle::flip() const { cout << \"whistle\" << endl; }\r\nvoid flip(const CWidget&#038; widget)\r\n{\r\n    widget.flip();\r\n}\r\n\r\nvoid main()\r\n{\r\n    CBell b;\r\n    CWhistle w;\r\n    flip(b);\r\n    flip(w);\r\n}\r\n<\/pre>\n<\/div>\n<span class=\"collapseomatic \" id=\"id6a1827a2349b5\"  tabindex=\"0\" title=\"cppom.mak\"    >cppom.mak<\/span><div id=\"target-id6a1827a2349b5\" class=\"collapseomatic_content \">\n<pre lang=\"dos\" line=\"1\">\r\nCC      = cl\r\nCFLAGS\t= \/EHsc \/Zi \/Fd \/c\r\nLD      = link\r\nLDARGS  = \/INCREMENTAL:NO \/DEBUG\r\nRM\t    = del \/q\r\n\r\n.cpp.obj::\r\n    $(CC) $(CFLAGS) $<\r\n\r\ntest1.exe: exp_def_ctor.obj\r\n\t$(LD) exp_def_ctor.obj $(LDARGS) \/OUT:test1.exe \/PDB:test1.pdb\r\n\r\nclean:\r\n\t$(RM) *.exe *.obj *.pdb *.idb *.ilk *.bak\r\n\r\nall: test1.exe\r\n<\/pre>\n<\/div>\n<br \/>\n<span class=\"collapseomatic \" id=\"id6a1827a2349e8\"  tabindex=\"0\" title=\"windbg results\"    >windbg results<\/span><div id=\"target-id6a1827a2349e8\" class=\"collapseomatic_content \">\n<pre lang=\"dos\">\r\n0:000> ln test1!main\r\nd:\\home\\desktop\\research\\exp_def_ctor.cpp(13)\r\n(01361080)   test1!main   |  (013610c0)   test1!std::endl\r\nExact matches:\r\n    test1!main (void)\r\n0:000> u 01361080 013610c0\r\ntest1!main [d:\\home\\desktop\\research\\exp_def_ctor.cpp @ 13]:\r\n01361080 55              push    ebp\r\n01361081 8bec            mov     ebp,esp\r\n01361083 83ec08          sub     esp,8\r\n01361086 8d4df8          lea     ecx,[ebp-8]\r\n01361089 e852000000      call    test1!CBell::CBell (013610e0)\r\n0136108e 8d4dfc          lea     ecx,[ebp-4]\r\n01361091 e86a000000      call    test1!CWhistle::CWhistle (01361100)\r\n01361096 8d45f8          lea     eax,[ebp-8]\r\n01361099 50              push    eax\r\n0136109a e8c1ffffff      call    test1!flip (01361060)\r\n0136109f 83c404          add     esp,4\r\n013610a2 8d4dfc          lea     ecx,[ebp-4]\r\n013610a5 51              push    ecx\r\n013610a6 e8b5ffffff      call    test1!flip (01361060)\r\n013610ab 83c404          add     esp,4\r\n013610ae 33c0            xor     eax,eax\r\n013610b0 8be5            mov     esp,ebp\r\n013610b2 5d              pop     ebp\r\n013610b3 c3              ret\r\n0:000> ln test1!CBell::CBell\r\n(013610e0)   test1!CBell::CBell   |  (01361100)   test1!CWhistle::CWhistle\r\nExact matches:\r\n    test1!CBell::CBell (void)\r\n0:000> u 013610e0 013610ff\r\ntest1!CBell::CBell:\r\n013610e0 55              push    ebp\r\n013610e1 8bec            mov     ebp,esp\r\n013610e3 51              push    ecx\r\n013610e4 894dfc          mov     dword ptr [ebp-4],ecx\r\n013610e7 8b4dfc          mov     ecx,dword ptr [ebp-4]\r\n013610ea e831000000      call    test1!CWidget::CWidget (01361120)\r\n013610ef 8b45fc          mov     eax,dword ptr [ebp-4]\r\n013610f2 c7005cd43701    mov     dword ptr [eax],offset test1!CBell::`vftable' (0137d45c)\r\n013610f8 8b45fc          mov     eax,dword ptr [ebp-4]\r\n013610fb 8be5            mov     esp,ebp\r\n013610fd 5d              pop     ebp\r\n013610fe c3              ret\r\n0:000> ln test1!CWidget::CWidget\r\n(01361120)   test1!CWidget::CWidget   |  (01361140)   test1!std::basic_ostream<char,std::char_traits<char> >::operator<<\r\nExact matches:\r\n    test1!CWidget::CWidget (void)\r\n0:000> u 01361120 0136113f\r\ntest1!CWidget::CWidget:\r\n01361120 55              push    ebp\r\n01361121 8bec            mov     ebp,esp\r\n01361123 51              push    ecx\r\n01361124 894dfc          mov     dword ptr [ebp-4],ecx\r\n01361127 8b45fc          mov     eax,dword ptr [ebp-4]\r\n0136112a c7006cd43701    mov     dword ptr [eax],offset test1!CWidget::`vftable' (0137d46c)\r\n01361130 8b45fc          mov     eax,dword ptr [ebp-4]\r\n01361133 8be5            mov     esp,ebp\r\n01361135 5d              pop     ebp\r\n01361136 c3              ret\r\n0:000> ln test1!flip\r\nd:\\home\\desktop\\research\\exp_def_ctor.cpp(8)\r\n(01361060)   test1!flip   |  (01361080)   test1!main\r\nExact matches:\r\n    test1!flip (class CWidget *)\r\n0:000> u 01361060 0136107f\r\ntest1!flip [d:\\home\\desktop\\research\\exp_def_ctor.cpp @ 8]:\r\n01361060 55              push    ebp\r\n01361061 8bec            mov     ebp,esp\r\n01361063 8b4508          mov     eax,dword ptr [ebp+8]\r\n01361066 8b10            mov     edx,dword ptr [eax]\r\n01361068 8b4d08          mov     ecx,dword ptr [ebp+8]\r\n0136106b 8b02            mov     eax,dword ptr [edx]\r\n0136106d ffd0            call    eax\r\n0136106f 5d              pop     ebp\r\n01361070 c3              ret\r\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8b49\u660e\u82e5 class \u5ba3\u544a\u6216\u7e7c\u627f virtual function \u6642\uff0c\u7de8\u8b6f\u5668\u6703\u81ea\u52d5\u751f\u6210 constructor<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/posts\/439"}],"collection":[{"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/comments?post=439"}],"version-history":[{"count":4,"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/posts\/439\/revisions"}],"predecessor-version":[{"id":444,"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/posts\/439\/revisions\/444"}],"wp:attachment":[{"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/media?parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/categories?post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cchsu.com\/arthur\/wp-json\/wp\/v2\/tags?post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}