Skip to content

Why is an explicit int conversion preferred over an implicit double conversion? #4520

Answered by svick
jnm2 asked this question in Q&A
Discussion options

You must be logged in to vote

I believe this happens because of these parts of the section Processing of user-defined explicit conversions in the spec (emphasis mine):

  • Find the set of applicable user-defined and lifted conversion operators, U. This set consists of the user-defined and lifted implicit or explicit conversion operators declared by the classes or structs in D that convert from a type encompassing or encompassed by S to a type encompassing or encompassed by T. […]
    […]
  • Find the most specific target type, TX, of the operators in U:
    • If any of the operators in U convert to T, then TX is T.
    • Otherwise, if any of the operators in U convert to types that are encompassed by T, then TX is the most encompassing ty…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jnm2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants