???C++????????
???????????? ???????[ 2013/4/11 10:19:27 ] ????????
???????????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: }
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11