vtbl of the subobject to the complete object

From: Marlene Miller <marlenemiller_at_worldnet.att.net>
Date: 12 Nov 2004 06:55:43 -0500


I am confused about the offset to the complete object in the vtbl of the subobject .

Re: The C++ Programming Language (Special Edition) 15.4.1 page 409-410.

class My_slider : public Ival_slider {

   // polymorphic base (Ival_slider has virtual functions)
}

void g(Ival_box* pb)
{

   My_slider* pd1 = dynamic_cast<My_slider*>(pb); //ok
}

There are two boxes labeled My_slider and vtbl. My_slider has an attribute vptr. There is a dotted arrow from the My_slider box to the vtbl box and a dashed arrow from the vtbl box to the My_slider box.

"The dashed arrow represents an offset that allows the start of the complete object to be found given only a pointer to a polymorphic sub-object."


  1. Is "a pointer to a polymorphic sub-object" referring to pb?
  2. Is "sub-object" referring to the base class sub-object of the My_slider object?
  3. Is "the complete object" referring to the My_slider object?
  4. Are they saying pb1 is a pointer to the My_slider object and not a pointer to the Ival sub-object?
  5. Are they saying given pb, we can navigate to the vtbl of the base class sub-object Ival, then navigate to the complete object My_slider?
  6. Does this imply, if we invoke a virtual function of Ival using pb that is overridden in My_slider, pb points to the base class sub-object, we navigate to the vtbl of this sub-object, then we navigate to the My_slider complete object, then we navigate to the vtbl of the My_slider object to get the implementation of the function?

Regards, Marlene

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
Received on Fri Nov 12 2004 - 03:52:03 PST

Click to report inappropriate content