Multiple Inheritance and Thunks
The g++ compiler implements the multiple inheritance of the classes B1
and B2
in class D
using two virtual method tables, one for each base class. (There are other ways to implement multiple inheritance, but this is the most common.) This leads to the necessity for "pointer fixups", also called thunks, when casting.
Consider the following C++ code:
D *d = new D; B1 *b1 = static_castWhile d
and b1
will point to the same memory location after execution of this code, b2
will point to the location d+8
(eight bytes beyond the memory location of d
). Thus, b2
points to the region within d
which "looks like" an instance of B2
, i.e., has the same memory layout as an instance of B2
.
Read more about this topic: Virtual Method Table
Famous quotes containing the words multiple and/or inheritance:
“Creativity seems to emerge from multiple experiences, coupled with a well-supported development of personal resources, including a sense of freedom to venture beyond the known.”
—Loris Malaguzzi (20th century)
“Someone in the crowd said to him, Teacher, tell my brother to divide the family inheritance with me. But he said to him, Friend, who set me to be a judge or arbitrator over you?”
—Bible: New Testament, Luke 12:13,14.
Jesus.