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.
A derived class is a class created or derived from another existing class. The existing class from which the derived class is created through the process of inheritance is known as a base class or superclass.
- A derived class is a class that inherits the properties from its super class. For example, a Cat is a super class and Monx cat is a derived class which has all properties of a Cat and does not have a tail.
The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.
Method Chaining For example, a method in a derived class might pre-process data into a standard form and then pass control to a method with the same name in a superclass. It's quite common for the same method name to be used in a class, one or more superclasses, and even one or more mixins.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With