6.4.3 User-defined implicit conversions
Visual Studio .NET 2003
A user-defined implicit conversion from type S to type T is processed as follows:
- Find the set of types,
D, from which user-defined conversion operators will be considered. This set consists ofS(ifSis a class or struct), the base classes ofS(ifSis a class), andT(ifTis a class or struct). - Find the set of applicable user-defined conversion operators,
U. This set consists of the user-defined implicit conversion operators declared by the classes or structs inDthat convert from a type encompassingSto a type encompassed byT. IfUis empty, the conversion is undefined and a compile-time error occurs. - Find the most specific source type,
SX, of the operators inU:- If any of the operators in
Uconvert fromS, thenSXisS. - Otherwise,
SXis the most encompassed type in the combined set of target types of the operators inU. If no most encompassed type can be found, then the conversion is ambiguous and a compile-time error occurs.
- If any of the operators in
- Find the most specific target type,
TX, of the operators inU:- If any of the operators in
Uconvert toT, thenTXisT. - Otherwise,
TXis the most encompassing type in the combined set of target types of the operators inU. If no most encompassing type can be found, then the conversion is ambiguous and a compile-time error occurs.
- If any of the operators in
- If
Ucontains exactly one user-defined conversion operator that converts fromSXtoTX, then this is the most specific conversion operator. If no such operator exists, or if more than one such operator exists, then the conversion is ambiguous and a compile-time error occurs. Otherwise, the user-defined conversion is applied:- If
Sis notSX, then a standard implicit conversion fromStoSXis performed. - The most specific user-defined conversion operator is invoked to convert from
SXtoTX. - If
TXis notT, then a standard implicit conversion fromTXtoTis performed.
- If