How does C++ determine implicit conversion/construction of objects few levels deep?
for example:
struct A {};
struct B: A {};
struct C { operator B() { return B(); } };
void f(A a) {}
int main(void)
{
f(C());
}
Does it create tree of all possible conversions and chooses appropriate terminal? Something else? Thanks
The call to
f()would need two conversions, one user-defined conversion (CtoB) and one built-in conversion (derived-to-base:BtoA). Calls with non-matching arguments succeed when they would need zero or one user-defined conversions. If different conversions (built-in or user-defined) would succeed, then, if all possible ways are equal in the number/kind of conversions they need, the call is ambiguous and the compiler needs to emit a diagnostic.How compilers implement this isn’t specified by the standard.