If a class has a single argument constructor my understanding is it is implicitly convertible by the constructor to the type of the argument in appropriate contexts. Defining a conversion operator also makes a class convertible to another type. Questions
I see I didn't understand clearly the directionality and that the two perform conversions in the opposite directions. As a follow on
These two are opposites: non-explicit one-argument constructor allows for automatic type conversion to your class type from argument type. Conversion operator allows for implicit casting from your class type.
Common wisdom is to avoid both if not specifically required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With