J
junyangzou
Say we have two base class Base1, Base2 and a Derived : public Base1, public Base2.
When we assign the address of a Derived Object to a Base2 Pointer. The address need to be adjust to the beginning of the Base2:
In my machine, the value of pBase2 and &d is 0079FAB0 0079FAB8 respectively, indicating that sizeof( Base1 ) is 8 bytes.
But when and where is the offset added? This can not be done in compiling time. Because though the example above is quite straightforward. Some times we may write code like:
We known the real type of the returned object only in rumtime. So anyone can explain when and where is the offset added? Thanks!
When we assign the address of a Derived Object to a Base2 Pointer. The address need to be adjust to the beginning of the Base2:
Base2 *pBase2;
Derived d;
pBase2 = &d;
In my machine, the value of pBase2 and &d is 0079FAB0 0079FAB8 respectively, indicating that sizeof( Base1 ) is 8 bytes.
But when and where is the offset added? This can not be done in compiling time. Because though the example above is quite straightforward. Some times we may write code like:
pBase2 = Factory.get();
We known the real type of the returned object only in rumtime. So anyone can explain when and where is the offset added? Thanks!