#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 conversion function above, the conversion constructor is assigned by my compiler (gcc 4.6.1), however in the standard it states that: p>
Custom conversions apply only where they are explicit
It would seem that in this case there is ambiguity. Can someone explain the contradiction?
I would expect the above to not compile. I'm also sure that a few years ago, Scott Meyers wrote about this particular example and said that it would not compile. What am I missing?
c ++ copy-constructor language-lawyer c ++ 11 implicit-conversion
Andrew Tomazos
source share