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?
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
|