class Yun
{
int q;
friend Yun operator+(const Yun& a, const Yun& b)
{
Yun c = a;
c.q += b.q;
return c;
}
public:
Yun(int i) :q(i) {
}
explicit operator int()
{
return q;
}
};
int main()
{
Yun y(3);
int w = y + 2;
return 0;
}
i make add the explicit to the operator int(),it will not be perform,why does compiler no choose the other way--performing Yun(int) to transform the second object--2.
And if i remove w value.
int main()
{
Yun y(3);
y+2;
return 0;
}
it can work,why?