Multiple inheritance and thunks

Assignment Help JAVA Programming
Reference no: EM13963511

Multiple Inheritance and Thunks

Suppose class C is de?ned by inheriting from classes A and B:

class A {
public:
virtual void g(); int x;
};
class B {
public:
int y;
virtual B* f(); virtual void g();
};
class C : public A, public B {
public:
int z;
virtual C* f(); virtual void g();
};
C *pc = new C; B *pb = pc; A *pa = pc;

and pa, pb,and pc are pointers to the same object, but with different types.

Then, pa and pc will contain the same value, but pb will contain a different value; it will contain the address of the B part of the C object. The fact that pb and pc do not contain the same value means that in C++, a cast sometimes has a run-time cost. (In C this is never the case.)

Note that in our example B::f and C::f do not return the same type. Instead, C::f returns a C* whereas B::f returns a B*. That is legal because C is derived from B, and thus a C* can always be used in place of a B*.

However, there is aproblem: When the compiler sees pb->f() it does not know whether the call will return a B* or a C*. Because the caller is expecting a B*, the compiler must make sure to return a valid pointer to a B*. The solution is to have the C-as-B vtable contain a pointer to a thunk. The thunk calls C:: f, and then adjusts the return value to be a B*, before returning.

(a) Draw all of the vtables for the classes in these examples. Show to which function each vtable slot points.

(b) Does the fact that casts in C++ sometimes have a run-time cost, whereas C never does, indicate that C++ has not adhered to the principles given in class for its design? Why or why not?

(c) Because thunks are expensive and because C++ charges programmers only for features they use, there must be a feature, or combination of features, that are imposing this cost. What feature or features are these?

Reference no: EM13963511

Questions Cloud

Do you have any experience with pci : Do you have any experience with PCI? Have you worked for an organization that dealt with PCI? HIPAA? SOX? What's your perspective on "compliance" versus "security" or risk reduction?
Depreciated for three years using the straight-line method : The old truck has been depreciated for three years using the straight-line method. The new truck would be recorded at
Create a proposal for vi walker silver web site : Creating a proposal for Vi Walker Silver (Links to an external site.) web site. Vi Walker Silver (Links to an external site.) is a local business that buys and sells sterling silver.
Craft a plan for identifying and monitoring risk : Project Risk Planning: Craft a plan for identifying and monitoring risk. In your plan, you could consider: The amount of uncertainty in the project and how to deal with it and The threats of greatest concern
Multiple inheritance and thunks : Then, pa and pc will contain the same value, but pb will contain a different value; it will contain the address of the B part of the C object. The fact that pb and pc do not contain the same value means that in C++, a cast sometimes has a run-time..
Reform of reimbursement systems for healthcare services : Reform of reimbursement systems for healthcare services provided to ambulatory patients began in 1992
Multiple inheritance and casts : An important aspect of C++ object and virtual function table (vtbl) layout is that if class D has class B as a public base class, then the initial segment of every D object must look like a B object, and similarly for the D and B virtual function ..
Consider two spin systems a and a'' placed in external field : In the most probable situation corresponding to the final thermal equilibrium, how is the energy Et of systemA related to the energy Et' of system A' ?
How elaborating evolution helps explain social change : Post an explanation of how elaborating evolution helps explain social change. Then, explain how elaborating evolutionary systems might inform how you, as a leader or manager, can enact positive social change

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java program that declares an array alpha

Write a java program that declares an array alpha to 50 elements of type double. Initialize the array so that the first 25 numbers are equal to the square of the index variable, and the last 25 elements are equal to 3 times the index variable. Output..

  Explain where the following method invocations

Explain where the following method invocations are most likely to be found in a program for dealing with census data organized using the Model, View, Controller (MVC) design pattern. Choices are zero or more of Model, View, and Controller. Be sure to..

  Develop the implementation file student.cpp

Required to implement the class to develop the implementation file Student.cpp that conforms to the following specifications

  Evaluate total annual compensation of a salesperson

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors: A salesperson will earn a fixed salary of $45,000

  Create a non-gui based java application

Create a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee.

  Write java program to store values retrieved from user-array

Write a Java program named Arrays6_2GF.java Use an array to store values retrieved from user input. The number of integers to be entered (the length of the array )should also be retrieved through user input.

  Xml assignment help please follow instructions in the

please follow instructions in the attached assignment instructions. ltbrgtplease follow instructions in the attached

  Review of classes-objects-arrays and enhance for looping

Write Java code for class Produce that meets the listed requirements

  Describe a multidimensional array

Describe a multidimensional array for a summer camp, the first array would be the number of kids say 30, then it would break them up by ages 6-9 (4 different groups) and lastly by sex m or f.

  Java program to implement currency converter

Write a JAVA program that helps the user convert currency. The user will enter the amount in Kuwaiti dinars. The program will print the equivalent amount in US dollar and Euros count his change.

  Write a program that takes input of names from user

Write a program that takes input of names from user. Print total names number and all names. NOTE: Solve this problem using ArrayList and Enhanced For Loop. Typical run of the program:Enter a name: (Q to exit)

  Write a java program that prompts the user

Write a Java program that prompts the user to input three numbers.  This program should then output the numbers in an ascending order.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd