+ 2

The overloaded constructor for rvalue reference is not getting invoked. Why ?

Check out the simple code.. https://code.sololearn.com/cIDjYxzs7QHA/?ref=app

2nd May 2020, 9:17 AM
Terminal_Phantom
Terminal_Phantom - avatar
8 ответов
+ 3
So you mean to say. There are some optimizations going on in my code.
2nd May 2020, 10:13 AM
Terminal_Phantom
Terminal_Phantom - avatar
+ 3
Pasting MyClass{MyClass{MyClass{MyClass{10}}}} to my code must invoke the constructor 4 times but it gets invoked only one time. Hence, I am 99.9% sure now it's optimization
2nd May 2020, 10:24 AM
Terminal_Phantom
Terminal_Phantom - avatar
+ 2
Well. I also think it is some optimization done by the compiler, to avoid : MyClass{MyClass{MyClass{MyClass{10}}}}
2nd May 2020, 9:58 AM
Terminal_Phantom
Terminal_Phantom - avatar
+ 2
MyClass class_5 = MyClass{10}; MyClass class_6 = MyClass{std::move(class_5)}; But, the upper one one Works as expected
2nd May 2020, 10:04 AM
Terminal_Phantom
Terminal_Phantom - avatar
+ 1
i think it because of copy elision..
2nd May 2020, 9:54 AM
durian
durian - avatar