#include <iostream>
using namespace std;
struct Y;
struct X
{
X(const Y&) { cout << "converting constructor" << endl; }
};
struct Y
{
operator X() { cout << "conversion function" << endl; }
};
void f(X x) {}
int main()
{
Y y;
f(y);
}
In the above the conversion function is given priority to the converting constructor by my compiler (gcc 4.6.1), however in the standard it states that:
User-defined conversions are applied only where they are unambiguous
It would seem that there is ambiguity in this case. Can anyone explain the contradiction?
I would have expected the above to not compile. I'm also pretty sure years ago that Scott Meyers wrote about this specific example and said that it wouldn't compile. What am I missing?