Doubt on move constructor | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Doubt on move constructor

Hi Refer attached code.... Display method has object as argument and it's call by value.... Due to this , r1 object calls copy constructor when it is passed to function argument... Now in second option , I have passed temporary object.... I thought it too should call copy constructor but it's not.... If it's not needed , why should we do have move constructor as without this also , we have only one object... To conclude , I thought I would need to have rvalue as display function argument to avoid copy constructor on temp object , but it's not case...

13th Jul 2020, 4:22 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Respuesta
+ 2
You would be correct however I think this falls under "copy elision", a compiler optimization technique which is even mandated by the standard.
14th Jul 2020, 7:39 AM
Schindlabua - avatar