In "C ++ Programming Language" 4th edition p. 164:
When we explicitly specify the type of object that we initialize, we must consider two types: the type of the object and the type of initializer. For instance:
char v1 = 12345;
int v2 = 'c';
T v3 = f();
Using the {} -initializer syntax for such definitions, we minimize the chances of bad conversions:
char v1 {12345};
int v2 {'c'};
T v3 {f()};
I do not quite understand the suggestion minimize the chances for unfortunate conversionsand comment for T v3 {f()};what it is works if and only if the type of f() can be implicitly converted to a T. Consider the following two cases:
- a) If T has an explicit constructor that takes an argument of type f ().
- b) If type f () has a transform operator of some type X, and T has a constructor that takes an argument of type X.
f() T, T v3 {f()} , , , only if ? ( , if).
T v3 = f();, , minimize the chances for unfortunate conversions? , {} - ( ). ( v1, . v3.)