Foo obj1(obj);
is direct initialization, Foo obj2 = obj;
is copy-initialization.
The only difference here is that the first can call explicit
constructors while the second cannot.
However, no sane person would make the copy constructor explicit
, so assuming that you are working with sane code it should make no difference. A class with an explicit copy constructor doesn't satisfy CopyConstructible
requirements (required for a number of standard container operations). Both function return and argument passing uses copy-initialization, so a class with an explicit copy constructor would not be usable in those contexts.
Just to make things crystal clear. N3936 §8.5 [dcl.init]/p15-16:
15 The initialization that occurs in the form
T x = a;
as well as in argument passing, function return, throwing an exception
(15.1), handling an exception (15.3), and aggregate member
initialization (8.5.1) is called copy-initialization. [ Note:
Copy-initialization may invoke a move (12.8). —end note ]
16 The initialization that occurs in the forms
T x(a);
T x{a};
as well as in new
expressions (5.3.4), static_cast
expressions
(5.2.9), functional notation type conversions (5.2.3), and base and
member initializers (12.6.2) is called direct-initialization.