I am trying to understand how C ++ compilers allow implicit conversions when there is a variable template constructor and a conversion operator. The following is a minimal example to illustrate:
When I write:
When I start, I get this output: B::operator A() const . Therefore, it uses a conversion operator (as I expected). Example in http://ideone.com/ZZ2uBz mode
But when A is a template, the result is different:
When I run this program, I get this output: A<tType>::A(tTypes ...) [with tTypes = {B}; tType = float] A<tType>::A(tTypes ...) [with tTypes = {B}; tType = float] . Thus, instead of the conversion operator to B , the variable constructor A . Example in http://ideone.com/u9Rxuh mode
Can someone explain to me why the difference? Should the conversion operator take precedence over the constructor?
I know that I could explicitly call the conversion operator ( A<float> a = b.operator A<float>(); ), but this is not what I want.
source share