How do standard conversions, user-defined conversions, explicit conversions, and narrowing participate in overload resolution?
Show answer and explanation
For each viable overload, C++ forms an implicit conversion sequence for every argument and ranks candidates using rules such as exact match, promotion, and conversion. A user-defined conversion sequence can use one converting constructor or conversion function with surrounding standard conversions; competing sequences can make a call ambiguous. Constructors or conversion functions declared explicit are excluded from ordinary implicit conversion contexts, though direct initialization and explicit casts can select them under their own rules. List initialization has special overload phases and rejects narrowing conversions, so braces can intentionally make an interface stricter than parentheses. A cast does not improve a bad ownership or range contract; it merely requests a particular conversion. Avoid broad implicit conversion operators and single-argument converting constructors unless substitutability is deliberate, use explicit to protect domain boundaries, and inspect the complete overload set rather than reasoning from the destination type alone.
For each viable overload, C++ forms an implicit conversion sequence for every argument and ranks candidates using rules such as exact match, promotion, and conversion. A user-defined conversion sequence can use one converting constructor or conversion function with surrounding standard conversions; competing sequences can make a call ambiguous. Constructors or conversion functions declared explicit are excluded from ordinary implicit conversion contexts, though direct initialization and explicit casts can select them under their own rules. List initialization has special overload phases and rejects narrowing conversions, so braces can intentionally make an interface stricter than parentheses. A cast does not improve a bad ownership or range contract; it merely requests a particular conversion. Avoid broad implicit conversion operators and single-argument converting constructors unless substitutability is deliberate, use explicit to protect domain boundaries, and inspect the complete overload set rather than reasoning from the destination type alone.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.