Does a C++ compiler automatically convert:
MyObject object2 = object1;
into
MyObject object2( object1 );
?
Or does it treat it like:
MyObject object2;
object2 = object1;
?
Yes, it's the first one. It's not an "optimisation"; they are two different syntaxes for invoking the copy constructor.
If you want to prove it, try defining a private assignment operator for MyObject. The code should still compile, which proves it can't be equivalent to the second mechanism.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With