typeid and TypeInfo
Explore how the Object class in D provides key member functions and how the typeid expression and TypeInfo class deliver runtime type information. Understand how to compare types and obtain runtime type names to enhance type handling in D programming.
We'll cover the following...
Object
Classes that do not explicitly inherit any class, automatically inherit the Object class.
By that definition, the topmost class in any class hierarchy inherits Object:
// Inherits Object indirectly
class StringInstrument : MusicalInstrument {
// ...
}
Since the topmost class inherits Object, every class indirectly inherits Object as well. In that sense, every class “is an” Object.
Every class inherits the following member functions of Object:
-
toString: The string representation of the object. -
opEquals: Equality comparison with another object. -
opCmp: Sort order comparison with another object. ...