The following code works fine:
and displays the result:
A(int, int)
Demo
But I canβt understand why? What the standard says:
However, when considering a constructor argument or a user-defined conversion function that is a candidate according to 13.3.1.3, when the class instance is initialized for copying / moving in the second stage, according to 13.3.1.7, when passing the initializer, the list as one argument or when the list of initializers has exactly one element and conversion to some class X or a reference to (possibly cv-qualified) X is considered for the first constructor parameter from X [...] only standard sequences are considered conversion lengths and ellipsis conversion sequences
So, in our case, we considered the constructor argument (it was {B(), B()} ). More precisely, we passed the list of initializers as one argument (the second case in the specified rule). Now we need to convert the first element of the initializer list (temporary type B ) to int , and the only way to do this is to use a user-defined conversion ( B::operator int() ). But, as said at the end of the rule that I called , only standard conversion sequences and ellipsis sequences were considered . Since this code should not work, it should cause an error, since A(int, int) not viable or kind.
What happened. Maybe this is a mistake?
user2953119
source share