toString and opEquals
Let’s learn about toString and opEquals functions for classes.
We'll cover the following...
toString
Same with structs, toString enables using class objects as strings. The following code shows how toString() is implicitly called when displaying class objects:
The inherited toString() is usually not useful; it produces just the name of the type:
deneme.Clock
Here deneme is the name of the module. The output above indicates that Clock has been defined in the deneme module.
As we have seen in the previous chapter, this function is almost always overridden to produce a more meaningful string representation of an object:
opEquals
As we have seen in the operator overloading chapter, this member function is about the behavior of the == operator (and the != operator indirectly). The return value of the operator must be true if the objects are considered to be equal and false otherwise.
Warning: ...