how is it legal to return any object other than Description?
You can return any type that's implicitly convertible to Description
. In this case, any numeric type can be converted to bool
via standard conversions, then to Description
via the non-explicit constructor.
You could prevent this conversion by declaring the constructor explicit
, if you like. It's a good idea to make that a habit, to avoid unexpected conversions like this one.
Does this mean a C++ compiler always calls the functions' return type constructor with the arguments of the return statement??
If the types don't match, and there is a suitable non-explicit constructor to use for the conversion, yes.
How did I not know that before?!
C++ is a complicated language. After fifteen years, I still keep finding things I didn't know.