March 2018
Intermediate to advanced
183 pages
2h 34m
English
Operator overloading allows operators to be redefined and used where one or both of the operands are of a user-defined class. When it’s done correctly, this can simplify the code and make user-defined types as easy to use as the primitive types.
In the following example there is a class called MyNum with an integer field and a constructor for setting that field. The class also has an addition method that adds two MyNum objects and returns the result as a new object.