0

Can u explain me?

I don't understand what is happening here Mystring is class has only single attribute char * str; Also it has all ctors(default, overloaded, copy, move, dtor...) In main.cpp Mystring obj(Mystring("This is string")); What is happening here?👆👆👆

16th Jun 2021, 11:08 AM
saurabh
saurabh - avatar
1 ответ
+ 3
Well, first you construct a temporary instance of Mystring using "This is string" as argument for the overloaded constructor, and afterwards, you construct a permanent instance from the temporary one. Since the first instance is about to be destroyed, this would invoke the move constructor. However, your compiler will probably optimize the line to a single call to the overloaded constructor.
16th Jun 2021, 2:38 PM
Shadow
Shadow - avatar