Question
4. Multiple inheritance I. In this exercise, we consider multiple inheritances. For simplicity, we assume that from each parent class B exactly one instance is
4. Multiple inheritance I. In this exercise, we consider multiple inheritances. For simplicity, we assume that from each parent class B exactly one instance is inherited by a subclass A, which means that each A-object contains exactly one B-subobject. For each parent class B of A, a fixed memory block is allocated within the memory block of an object of class A. Also, we assume that the first immediate parent class B1 is treated like the immediate parent class in the case of single inheritance: its memory block is located at the beginning of the memory block for the immediate subclass A (Fig. 5.6). For a parent class Bi,the Bi-view to an object of class A is obtained by placing a pointer at the start of the block designated for Bi. Accordingly, the A-view to the object agrees with the B1-view for the first immediate parent class B1 of A. Within the memory block for A, a reference to the table tA of all virtual functions known in A is stored in location 0. At the beginning of all parent classes Bi which are not the first immediate parent class, a reference to a table tA,Bi is stored. The table tA,Bi contains the start addresses of all methods of A that are known in Bi. This construction is recursively applied to all parent classes of immediate parent classes Bi of A, and so on. A method f known in Bi may have been overloaded by the subclass A. Thus in tA,Bi , not only the start address of f must be recorded, but also the distance between the memory blocks for the classes A and Bi. This allows us to construct before the call to f, from Bi the correct A-view to the A-object.
a) Complete the details of the definitions of the tables tA,Bi . Implement the type cast of a pointer to an A-object to a pointer to an object of a super-and a subclass of A, respectively.
b) Discuss strategies for resolving name conflicts and sketch their implementations.
c) Combine the basic principle for multiple inheritance with our former trans-lation schemes.
d) Test your new translation schemes on our example class library.
ta t A,B2 HH B1 B2 A Fig. 5.6. The object organization for two parent classes ta t A,B2 HH B1 B2 A Fig. 5.6. The object organization for two parent classesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started