+ 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... https://code.sololearn.com/cURqEtILew2F/?ref=app
1 Réponse
+ 2
You would be correct however I think this falls under "copy elision", a compiler optimization technique which is even mandated by the standard.
https://en.cppreference.com/w/cpp/language/copy_elision