I use VC6+SP4
the simple situation:
class Base {};
class Child : virtual public Base {};
void main() {Child c;}
|
in VC's watch window i got these :
sizeof(Base) 1 // i know this, compiler need a address
sizeof(Child) 4 // not VPTR for VTABLE, here's no virutal method.
&c 0012ff7c
0012ff7c 0043101c // suppose to be a pointer, so i go:
0043101c blah~~~~ // confused
here comes the complicated situation:
class Base {};
class Child1 : virtual public Base {};
class Child2 : virtual public Base {};
class Final : public Child1, public Child2 {};
void main() {Final f;}
|
now is :
sizeof(Base) 1
sizeof(Child1) 4
sizeof(Child2) 4
sizeof(Final) 8
&f 0x0012ff78
0012ff78 28 20 42 00 1C 20 42 00 // only 8 bytes are useful
0042201c 00 00 00 00 04 00 00 00 00 00 00 00
00422028 00 00 00 00 08 00 00 00 00 00 00 00
ok, by now i know that the first DWORD of f must be some kind pointer like VPTR, it point to a group of pointer which each point to a DWORD array which contains 3 elements and the second item seems like a offset value.
my question is, when and why the executable will use these fields?
why ask this? as for multiple inheritance, to avoid ambiguous when we call a function which occurs in both base class, we need to give the namespace qualifier, such as Child1::f() or Child2::f(); and another thing, the "virtual" keyword used for "eliminate the dup-subobject". but both of the two are all accomplished at compile-time, so the question arised : when and why the executable will use these fields?
i read ISO-Spec/Book by BjornStr./Book by Eckel/...., no result, so i come here and post this...
any tips should be appreciated!
Edited by - ed9er on February 22, 2001 10:14:23 AM
------------------------------------------------------CCP is fascistic, they even banned www.sourceforge.net