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