s******n 发帖数: 3946 | 3 When compiler handles b->func(para1, para2), it assumes the address is like
this
vptr_BClass
B data member 1
B data member 2
The call will be translated like this:
((vptr_BClass*)b)[0] -> func (b, para1, para2)
class C extends B & A, then memory layout is like this:
vptr_AClass
A data member 1
A data member 2
vptr_BClass
B data member 1
B data member 2
When we do B* b= &c, compiler will add offset to skip the A part. So a
later call b->func() can be handled in the same way for all subclass... 阅读全帖 |
|