March 2018
Intermediate to advanced
183 pages
2h 34m
English
Custom type conversions can be defined to allow an object to be constructed from or converted to another type. In the following example, there is a class called MyNum with a single integer field. With conversion constructors, it is possible to allow integer types to be implicitly converted to this object’s type.
For this type of conversion to work, a constructor needs to be added that takes a single parameter of the desired type , in this case an int.