This works because A has a single argument constructor, which C ++ uses as the transform constructor:
A constructor that is not declared by the explicit specifier and which can be called with one parameter (before C ++ 11) is called a conversion constructor. Unlike explicit constructors, which are only considered in direct initialization (including explicit conversions such as static_cast), transform constructors are also considered during copy initialization as part of a custom transform sequence.
This is why C ++ can interpret test(b, &i) as test(A(b), &i) .
If you do not want this behavior, mark the A constructor explicit .
source share