The following two code segments presents the task of initializing variable b
as a copy of a
. The first code segment initializes the variable using copy initialization (initialization using =
). Assume class Apple
is simply defined as an empty class: class Apple {};
Apple a;
Apple b = a;
The second code segment initializes the variable using copy initialization as well. Though what is copied in the initialization is the copy of a
.
Apple a;
Apple b = Apple(a);
When reading this blindly, it seems as if a copy happens at Apple(a)
, and another at Apple b = ...
. In contradiction, overriding the copy constructor of Apple
to print something on copy shows that only one copy happens during Apple b = Apple(a)
.
Are the two statements Apple b = a;
and Apple b = Apple(a);
identical? Are there instances where they are not identical?