cpp/language/copy initialization

Initializes an object from another object.

Explanation
Copy initialization is performed in the following situations: @1@ When a named variable (automatic, static, or thread-local) of a non-reference type is declared with the initializer consisting of an equals sign followed by an expression. @2@ When a named variable of a scalar type  is declared with the initializer consisting of an equals sign followed by a brace-enclosed expression (Note: as of C++11, this is classified as, and narrowing conversion is not allowed). @3@ When to a function by value. @4@ When from a function that returns by value. @5@ When or  an exception by value. @6@ As part of, to initialize each element for which an initializer is provided.

The effects of copy initialization are:


 * Otherwise, if is a class type and the cv-unqualified version of the type of  is  or a class derived from, the  of  are examined and the best match is selected by overload resolution. That constructor is then called to initialize the object.


 * Otherwise, if is a class type, and  the cv-unqualified version of the type of  is not  or derived from, or if  is non-class type, but the type of  is a class type,  that can convert from the type of  to  (or to a type derived from  if  is a class type and a conversion function is available) are examined and the best one is selected through overload resolution. The result of the conversion, which is a  of the cv-unqualified version of  if a  was used, is then used to  the object.


 * Otherwise (if neither nor the type of  are class types),  are used, if necessary, to convert the value of  to the cv-unqualified version of.