tmp/tmpdy9t8nuw/{from.md → to.md}
RENAMED
|
@@ -6,43 +6,42 @@ argument list for a constructor that is called to initialize the object.
|
|
| 6 |
Alternatively, a single *assignment-expression* can be specified as an
|
| 7 |
*initializer* using the `=` form of initialization. Either
|
| 8 |
direct-initialization semantics or copy-initialization semantics apply;
|
| 9 |
see [[dcl.init]].
|
| 10 |
|
|
|
|
|
|
|
| 11 |
``` cpp
|
| 12 |
struct complex {
|
| 13 |
complex();
|
| 14 |
complex(double);
|
| 15 |
complex(double,double);
|
| 16 |
};
|
| 17 |
|
| 18 |
complex sqrt(complex,complex);
|
| 19 |
|
| 20 |
-
complex a(1); // initialize by a call of
|
| 21 |
-
// complex(double)
|
| 22 |
complex b = a; // initialize by a copy of a
|
| 23 |
-
complex c = complex(1,2); // construct complex(1,2)
|
| 24 |
-
// using complex(double,double)
|
| 25 |
// copy/move it into c
|
| 26 |
-
complex d = sqrt(b,c); // call sqrt(complex,complex)
|
| 27 |
-
|
| 28 |
-
complex
|
| 29 |
-
|
| 30 |
-
complex f = 3; // construct complex(3) using
|
| 31 |
-
// complex(double)
|
| 32 |
-
// copy/move it into f
|
| 33 |
-
complex g = { 1, 2 }; // initialize by a call of
|
| 34 |
-
// complex(double, double)
|
| 35 |
```
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
An object of class type can also be initialized by a *braced-init-list*.
|
| 41 |
List-initialization semantics apply; see [[dcl.init]] and
|
| 42 |
[[dcl.init.list]].
|
| 43 |
|
|
|
|
|
|
|
| 44 |
``` cpp
|
| 45 |
complex v[6] = { 1, complex(1,2), complex(), 2 };
|
| 46 |
```
|
| 47 |
|
| 48 |
Here, `complex::complex(double)` is called for the initialization of
|
|
@@ -58,17 +57,21 @@ struct X {
|
|
| 58 |
} x = { 99, 88.8, 77.7 };
|
| 59 |
```
|
| 60 |
|
| 61 |
Here, `x.i` is initialized with 99, `x.f` is initialized with 88.8, and
|
| 62 |
`complex::complex(double)` is called for the initialization of `x.c`.
|
| 63 |
-
Braces can be elided in the *initializer-list* for any aggregate, even
|
| 64 |
-
if the aggregate has members of a class type with user-defined type
|
| 65 |
-
conversions; see [[dcl.init.aggr]].
|
| 66 |
|
| 67 |
-
|
| 68 |
-
an object of type `T` (or array thereof) is ill-formed if no
|
| 69 |
-
*initializer* is explicitly specified (see [[class.init]] and
|
| 70 |
-
[[dcl.init]]).
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
|
|
|
| 6 |
Alternatively, a single *assignment-expression* can be specified as an
|
| 7 |
*initializer* using the `=` form of initialization. Either
|
| 8 |
direct-initialization semantics or copy-initialization semantics apply;
|
| 9 |
see [[dcl.init]].
|
| 10 |
|
| 11 |
+
[*Example 1*:
|
| 12 |
+
|
| 13 |
``` cpp
|
| 14 |
struct complex {
|
| 15 |
complex();
|
| 16 |
complex(double);
|
| 17 |
complex(double,double);
|
| 18 |
};
|
| 19 |
|
| 20 |
complex sqrt(complex,complex);
|
| 21 |
|
| 22 |
+
complex a(1); // initialize by a call of complex(double)
|
|
|
|
| 23 |
complex b = a; // initialize by a copy of a
|
| 24 |
+
complex c = complex(1,2); // construct complex(1,2) using complex(double,double),
|
|
|
|
| 25 |
// copy/move it into c
|
| 26 |
+
complex d = sqrt(b,c); // call sqrt(complex,complex) and copy/move the result into d
|
| 27 |
+
complex e; // initialize by a call of complex()
|
| 28 |
+
complex f = 3; // construct complex(3) using complex(double), copy/move it into f
|
| 29 |
+
complex g = { 1, 2 }; // initialize by a call of complex(double, double)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
```
|
| 31 |
|
| 32 |
+
— *end example*]
|
| 33 |
+
|
| 34 |
+
[*Note 1*: Overloading of the assignment operator ([[over.ass]]) has
|
| 35 |
+
no effect on initialization. — *end note*]
|
| 36 |
|
| 37 |
An object of class type can also be initialized by a *braced-init-list*.
|
| 38 |
List-initialization semantics apply; see [[dcl.init]] and
|
| 39 |
[[dcl.init.list]].
|
| 40 |
|
| 41 |
+
[*Example 2*:
|
| 42 |
+
|
| 43 |
``` cpp
|
| 44 |
complex v[6] = { 1, complex(1,2), complex(), 2 };
|
| 45 |
```
|
| 46 |
|
| 47 |
Here, `complex::complex(double)` is called for the initialization of
|
|
|
|
| 57 |
} x = { 99, 88.8, 77.7 };
|
| 58 |
```
|
| 59 |
|
| 60 |
Here, `x.i` is initialized with 99, `x.f` is initialized with 88.8, and
|
| 61 |
`complex::complex(double)` is called for the initialization of `x.c`.
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
— *end example*]
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
[*Note 2*: Braces can be elided in the *initializer-list* for any
|
| 66 |
+
aggregate, even if the aggregate has members of a class type with
|
| 67 |
+
user-defined type conversions; see [[dcl.init.aggr]]. — *end note*]
|
| 68 |
+
|
| 69 |
+
[*Note 3*: If `T` is a class type with no default constructor, any
|
| 70 |
+
declaration of an object of type `T` (or array thereof) is ill-formed if
|
| 71 |
+
no *initializer* is explicitly specified (see [[class.init]] and
|
| 72 |
+
[[dcl.init]]). — *end note*]
|
| 73 |
+
|
| 74 |
+
[*Note 4*: The order in which objects with static or thread storage
|
| 75 |
+
duration are initialized is described in [[basic.start.dynamic]] and
|
| 76 |
+
[[stmt.dcl]]. — *end note*]
|
| 77 |
|