Multiple inheritance and casts

Assignment Help JAVA Programming
Reference no: EM13963509

C++ 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 tables. The reason is that this makes it possible to access any B member data or member function of a D object in exactly the same way we would access the B member data or member function of a B object. Although this works out fairly easily with only single inheritance, some effort must be put into the implementation of multiple inheritance to make access to member data and member functions uniform across publicly derived classes.

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

class A {

public:

int x;

virtual void f();

};

class B {

public:

int y;

virtual void f(); virtual void g();

};

class C : public A, public B  {

public:

int z;

virtual void f();

};

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. The representation of this object of class C and the values of the associated pointers are illustrated in this chapter.

(a) Explain the steps involved in ?nding the address of the function code in the call pc->f(). Be sure to distinguish what happens at compile time from what happens at run time. Which address is found, &A : : f(), &B : : f(), or &C : : f()?

(b) The steps used to ?nd the function address for pa->f() and to then call it are the same as for pc->f(). Brie?y explain why.

(c) Do you think the steps used to ?nd the function address for and to call pb->f() have to be the same as the other two, even though the offset is different? Why or why not?

(d) How could the call pc->g() be implemented?

Reference no: EM13963509

Questions Cloud

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
Find recent news that involves information security : For this assignment, you need to find recent news that involves information security breaches. This news must not be older than one year. Then you need to analyse the chosen news and write a report on it. The report should include but not limited to ..
Subtyping and binary methods : This question is about the relationship between subtyping and inheritance. Recall that the main principle associated with subtyping is substitutivity: If A is asubtype of B, then wherever a B object is required in a program

Reviews

Write a Review

JAVA Programming Questions & Answers

  Digital image processing using java

Digital image processing using java ..create plugin using Jedit and run it in imageJ

  Design and implement a small and simple email server using

design and implement a small and simple email server using the concept of web based information system wbis. your

  Write a program called drawing in the form of a public class

Write a program called Drawing in the form of a public class Drawing that extends a Java JFrame and provides the following features.

  What is a generic subprogram in java

How do you describe as a type in C++ a pointer to a function that takes two ints as arguments and returns a double. What is a generic subprogram in Java. What are its advantages

  When are stubs & skeletons created for my ejb components

When are stubs & skeletons created for my EJB components? is it at development time, deployment time or run time?

  Calculate and display the total retail value of all products

Your application must calculate and display the total retail value of all products sold after all five pairs of inputs are completed - Write a Java application that prompts the user for pairs of inputs of a product number

  Write a java app that allows user to input grocery orders

Write a java application that allows the user to input and validate Order details of online grocery orders for N customers. The N should be set as a constant (final) in your application.

  Swing gui java application running with eclipse on windows x

To test the program just start MoneyMain to see if you click the icons for the detail screens and click Report to view the two reports.

  Echo client-server application

ASSIGNMENT 1- An echo client-server application, You are required to develop an application that allows clients running on MS Windows platforms to send sequences of strings to an echo server running on a windows platform

  Write a program using bucket sort idea to create histograms

The input data are in an external file named election.txt. The first line is an integer N representing the number of candidates. The next N lines are the names of the canditates.

  Comparator that compares point objects by their distance

write a comparator that compares point objects by their distance from the origin of (0,0). points that are closer to the origin are considered to come before those which are further from the origin

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