C c4 = c1;
is Copy Initialization.
It tries to convert c1
to an type C
if it is already of not that type by finding a suitable conversion function and then uses the the created C
instance for copy constructing a new C
instance.
Note that though,
C c4(c1);
is Direct Initialization
And it is important to note that there is a difference between Copy Initialization and Direct Initialization they are not the same!
Why C c4 = c1;
is syntactically equivalent to C c4(C1)
and not C C4; c4 = c1;
Why was it made that way?
First, Copy Initialization & Direct Initialization are not the same.
As to the rationale of why no assignment operator is called, assignment only occurs when one assigns two completely formed objects to each other.
In case of:
C c4 = c1;
c1
is a completely constructed object while c4
yet does not exist all, When such an scenario arises and =
is present, it doesn't really mean Assignment but it means Initialization.
So Basically, what happens here is Initialization and not Assignment and the C++ Standard defines specific rules as to how this initialization should be done.