???????????Child?????????????????????沼?????????????????????????__vfptr??iA_??iB_??iC_??

?????á??????????Child?????Father??????Father???????????Child???????????Σ???????????Father??????Child???????????FuncA()??????????????????Father?????__vfptr??Child??????????????????FuncA()????this???λiA_??iB_????????????

???????????????FuncA()????????????iA_??iB_?????????Child?????????FuncA??????????????????????????????????????????????

???????????????????Father??????????麯??????????Father??????????麯??????£??????FuncA?е??á?

????????????????????

1: #include <stdio.h>
2:
3: class Base
4: {
5: public:
6:     virtual void ShowID()
7:     {
8:         printf("Base ");
9:     }
10: };
11:
12: class CB : public Base
13: {
14: public:
15:     virtual void ShowID()
16:     {
17:         printf("CB ");
18:     }
19: };
20:
21: class CC : public Base
22: {
23: public:
24:     virtual void ShowID()
25:     {
26:         printf("CC ");
27:     }
28: };
29:
30: void Test( CB& oB )
31: {
32:     oB.ShowID();
33: }
34:
35: int main()
36: {
37:     Base oBase;
38:     CB    oB;
39:     CC    oC;
40:
41:     CB* pCB = &oB;
42:
43:     *(int*)(&oB) = *(int*)(&oC);    //?????????
44:     oB.ShowID();
45:     ((CB*)(&oB))->ShowID();
46:     pCB->ShowID();
47:     Test(oB);
48:
49:     return 0;
50: }