17

The C++03 Standard states §1.8 [intro.object]/4:

If a complete object, a data member (9.2), or an array element is of class type, its type is considered the most derived class, to distinguish it from the class type of any base class subobject; an object of a most derived class type is called a most derived object.

Can anyone shed some light on the "most derived object"? Some examples would be very appreciated.

1 Answer 1

16

The quote is defining the meaning of most derived class to be the class of the object being instantiated. While an object can be of many types, as inheritance models the is-a relationship, it will only have one most derived class.

With an example:

class base {};
class derived : base {};
class base2 {};
class mostderived : derived, base2 {};

mostderived md;

The object md is of most derived class mostderived, although it is also of types base, derived and base1. When talking about md, there is a subobject of type base, a subobject of type derived (that includes the subobject of type base), and a subobject of type base2, but only one most derived object that is md of type mostderived.

1
  • 1
    follow-up to this: if there are two such classes, mostderived1 and mostderived2, and subsequently two objects md1 and md2, are they both considered "most-derived"?
    – aspen100
    Sep 4, 2018 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.