Is there a difference between the 2 initailizations of an object.
Object obj(constructor_arguments);
or
Object obj = Object(constructor_arguments);
Note that the second initialization is not intended to be a pointer with the new
operator. It is intended to be a non heap variable.
In GCC both compile and work fine and I'm wondering if there is actually any difference or if both statements are semantically the same.
Yes there is. The first is the syntax for direct initialization, the second is copy initialization.
Theoretically, the second one calls the copy constructor, but this is subject to optimizations.
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