What does a conversion constructor look like with more than one optional parameter, and why does it make sense?

As far as I used "converting constructors", they look like this:

struct X { X(A); // conversion from A -> X X(B,C = someC); // conversion from B -> X, with some default C }; X x1 = A(); // calls X::X(A()) X x2 = B(); // calls X::X(B(),someC) 

This makes sense, and as far as I know, it works until you have a constructor:

 struct Y { Y(A,B); // no implicit conversion }; 

However, this is where it gets interesting, the C ++ 11 standard reads literally:

12.3.1 Constructor Conversion

  • A constructor declared without an explicit specifier function that can be called with one parameter indicates the conversion from the type of its first parameter to the types of its parameters into the type of its class. Such a constructor is called a transform constructor.

(italics were initially emphasized, but markdown does not accept <u> )

This, apparently, suggests that the conversion constructor should not be called “with one parameter”, but a change from “the type of its first parameter” to “type s of its parameters” (note the plural !). Although I would expect that the "type of its first parameter" will be changed to "the type of its one optional parameter" (1) or even "the type of its parameter that received an explicit argument" (2) to allow these

 struct Z { Z(A = a, B, C = c); // (1) Z(D = d, E = e, F = f); // (2) }; Z = D(); // (2) Z = E(); // (2) 

I don’t see how a wording with multiple forms makes sense: Does this mean that you can perform the conversion with several arguments? What does it mean?

+7
source share
1 answer

The language has been changed as part of adding initializer lists. See n2672: wording of the initials list .

Example:

 struct S { S(int x, double y) { } }; void f(S) { } int main() { f({ 42, 42.0 }); } 
+10
source

All Articles