The main differences between direct initialization and initialization of a copy are described in paragraph 17 of standard 8.5 of the standard. In general, the difference is that for class types during copy-initialization explicit constructors are not considered (only constructor conversions are taken into account) and, possibly, the copy is fixed; direct initialization considers explicit constructors, and the goal is built directly. From section 8.5 of the standard:
14 - The initialization form (using parentheses or = ) is usually not significant, but it matters when the initializer or the object being initialized has the class type [...]
For nonclass types (including references), direct initialization and copy-initialization have similar semantics; for links, linking occurs in any case, as specified in 8.5.3 Links [dcl.init.ref] . Direct initialization and copying of link initialization have only different semantics in which the conversion function is involved ( 13.3.1.6 Initialization using the conversion function for direct link binding [over.match.ref] ); again, direct initialization is allowed to call explicit conversion functions where copying is not performed.
So in
int &j = i;
8.5.3p5 is applied, and the link j bound directly to lvalue i . No temporary numbers are called.
In terms of complexity, references are closer to fundamental (primitive) types than to class types. Primitives are initialized without a temporary build (8.5p17, the last bullet), and in general, links too. This is probably why the book uses the form = to initialize links; as with primitives, there is usually no difference, and the entry is int i = x; usually clearer than int i(x); .
ecatmur
source share