T a( b );
- This is direct initialization if it does not parse as a function declaration, in which case it is a function declaration.
T a = b;
- This is the initialization of the copy, which means that it works as if the temporary object was built on the right side, and that a then copied either in C ++ 11 and later versions, possibly temporary.
The compiler is free to delete (delete) temporary + copy / move whenever possible, but the copy or move constructor, whatever it is logically used, should be available, not explicit .
For example, in C ++ 03 you cannot copy-initialize std::ostringstream because it does not have a copy constructor. In C ++ 11, you can copy ostringstream initialization if the initializer is temporary, which leads to a logical move construct (which will usually be eliminated, optimized). For example, this is a copy initialization declaration,
ostringstream s = ostringstream( "blah" );
& hellip; does not compile as C ++ 03, because in C ++ 03, initializing a copy calls the constructor of an instance of a class that does not exist. However, it compiles as C ++ 11 because in C ++ 11, initializing the copy calls the move constructor. Although (to preserve the illusion of a stream), std::ostringstream cannot be copied directly, it can be moved.
Another such difference: in C ++ 03, only copy initialization syntax supports italic curly braces initializers, which in C ++ 03 can be used when T is an aggregated type, such as an raw array. In C ++ 11, the curly brackets have been expanded and generalized as uniform initialization syntax, so it can also be used with direct initialization. So, the following direct initialization declaration,
int v[]{ 3, 1, 4, 1, 5, 9, 2, 6, 5, 4 };
& hellip; does not compile as C ++ 03, but compiles as C ++ 11 and later.
Copy Initialization Syntax = is the initial initialization syntax from C.
And in C ++ 11 and later, because of the semantics of movement, it can be used in a much wider range of cases than in C ++ 03, for example, with std::ostringstream .