Let's say we have class X with defined constructor X(int value)
.
Is this semantically equivalent or not?
X x = 42;
X x(42);
I believe the difference will appear only if we add explicit keyword to constructor of X.
Otherwise compiler will reduce expression X x = 42;
to X x(42);
Please, correct me if I'm wrong.
The form
X x = 42;
requires that the constructor be non-explicit and that there be an accessible copy-constructor. The implementation is allowed to construct a temporary and copy it over, but no implementation I know of does that.
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