Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "most derived object" mean?

Tags:

c++

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.

like image 618
Derui Si Avatar asked Sep 03 '12 03:09

Derui Si


People also ask

What is a derived class object?

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.

What is derived class with example?

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

What is derived class in inheritance?

The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.

What is derived method?

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.


1 Answers

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.

like image 168
David Rodríguez - dribeas Avatar answered Oct 14 '22 23:10

David Rodríguez - dribeas