ADT conversions - Quiz Explanation
The correct answers are indicated below, along with the text that explains the correct answers.
1.
Explicit cast conversion is necessary:
A.
anytime an int needs to be converted to a double
B.
anytime any native type needs to be converted to another native type
C.
anytime a user-defined type is used as an argument to a function
D.
when the implicit conversion is not desired or expression is illegal otherwise
The correct answer is D.
Explicit cast conversion should rarely be used, however.
2.
A constructor is a conversion constructor if:
A.
it takes two arguments: the "from-type" and "to-type"
B.
it has only one "from-type" argument and the "to-type" is implied
C.
it takes either two arguments or it takes only the "from-type" argument
D.
the constructor has no arguments and is made for you by the compiler
The correct answer is B.
A constructor of one argument is a conversion from that argument type to the class type.
3.
To convert from a user-defined type to a built-in type, you must add a special conversion member function to the class. This member function must:
A.
use the operator keyword in its declaration
B.
be a static member function
C.
have a return type
D.
not have an empty argument list
The correct answer is A.
A member function that is designed to convert from a user-defined type to a built-in type must use the keyword operator. It must also be a nonstatic member function without a return type and with an empty argument list.