For the foo object in the expression foo + 1 the implicit conversion operator will be called: operator int().
The line explicit A (int a); prevents the compiler from trying to call a constructor of implicit conversion to an object of type A for the integer constant 1 in the expression foo + 1.
Thus, we get rid of the ambiguity for the expression foo + 1 and the compiler implicitly converts foo to a value of type int and not vice versa.
Login in to like
Login in to comment