So to explore more about overload resolution process I was reading this article : http://accu.org/index.php/journals/268
Particularity "Ordering of User-Defined Conversion Sequences" section has this example :
struct A;
struct B {
B(A const&);
};
struct A {
operator B() const;
operator int() const;
};
void func(B);
void func(int);
func(A());
Initially I thought call is ambiguous because of following conversion operators in struct A
operator B() const; //-> A::operator B(const A&)
operator int() const; //-> A::operator int(const A&)
Then they explained like this :
The call is ambiguous, however, the parameter B has an ambiguous conversion sequence and if the function having this parameter was eliminated the call would not be ambiguous. This is because there would be only one function to select.
Which totally went top of my head, so I thought I should stand up and read it again but still it eluded me grins
I really would appreciate if one could explain order of event and what above quoted para from article meant in simple term please :) Thanks a lot :)
It's attempting to illustrate the point made in the previous paragraph in the article.
You can never successfully pass an A
to void func(B)
because of the ambiguous conversion sequence you've identified. But for overload resolution purposes that overload is still considered viable.
If instead it was removed from the viable set then the call to func
would unambiguously call void func(int)
because there was no other choice. That probably isn't the right thing to do.