Derived的内存布局:
class Derive size(20):
+---
| +--- (base class Base2)
0 | | {vfptr}
4 | | {vbptr}
| +---
| +--- (base class Base3)
8 | | {vbptr}
| +---
+---
+--- (virtual base Base1)
12 | {vfptr}
16 | i
+---
Derive::$vftable@Base2@:
| &Derive_meta
| 0
0 | &Base2::f1
1 | &Derive::g1
Derive::$vbtable@Base2@:
0 | -4
1 | 8 (Derived(Base2+4)Base1)
Derive::$vbtable@Base3@:
0 | 0
1 | 4 (Derived(Base3+0)Base1)
Derive::$vftable@Base1@:
| -12
0 | &Derive::f
1 | &Derive::g
2 | &Base3::h//不注释掉virtual void h(){ cout<<"Base2::h"<<endl;},则因该处不知填入Base2::h,还是Base3::h,而编译不了。
Derive::f this adjustor: 12
Derive::g this adjustor: 12
Derive::g1 this adjustor: 0
vbi: class offset o.vbptr o.vbte fVtorDisp
Base1 12 4 4 0
有关该问题,可查看http://topic.youkuaiyun.com/u/20091028/10/da703f45-0765-4c4c-8ed2-df287a6f86a0.html