problem with move ctor and dtor | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

problem with move ctor and dtor

Line no 113 to 116 student g1(student("Larry"));//why move ctor is not called after overloaded ctor??? g1.display(); student g2 = "Delta";//Also here,why move ctor is not called after overloaded ctor??? g2.display(); Also why dtor is not called for unnamed temporary objects created just before display is invoked???? for more info, refer https://code.sololearn.com/ca23a14A18A6/?ref=app

19th Jun 2021, 11:42 AM
saurabh
saurabh - avatar
3 Answers
+ 1
Copy elision dictates that a compiler has to omit copy/move constructors in some situations, in which case the instance is directly initialized. This is the case for both lines of code you mentioned, and also the reason no destructor is called; a temporary object was never constructed. For more information, you can refer here: https://en.cppreference.com/w/cpp/language/copy_elision The following thread on StackOverflow is also aimed at an explanation of the topic: https://stackoverflow.com/questions/12953127/what-are-copy-elision-and-return-value-optimization
19th Jun 2021, 9:18 PM
Shadow
Shadow - avatar
0
Please tell me what's happening with me? I am trying to attach my code but after attaching i see that that is a python code by Jeremy Petrie. I have reattached my cpp code but again same problem . Please help me
19th Jun 2021, 11:53 AM
saurabh
saurabh - avatar
0
Now i closed app then reopened and reattached my code. Now it's attached, fine. But i don't know what was happening with me while attaching code,i attached my code ,but shows python code by Jeremy Petrie....
19th Jun 2021, 11:58 AM
saurabh
saurabh - avatar