Deep copy memory issue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Deep copy memory issue

Tried copy constructor but getting memory issue What's wrong here? https://code.sololearn.com/cJzDGiQ1UtM9/?ref=app

30th Apr 2022, 9:51 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 1
At the moment, you just copy the pointer, not the object, and delete that before the second call to display(), which is undefined behaviour. In order to call the copy constructor, you would have to write: clsTest* p2 = new clsTest(*p1);
1st May 2022, 8:06 AM
Shadow
Shadow - avatar
+ 1
I see your questions in my feed, but not in the Q&A most recent view. Strange.
30th Apr 2022, 10:14 AM
Paul
Paul - avatar
0
It seems some issue with sololearn now a days.... I already informed them about other issue that is missing code lines when saved from windows laptop and checked on android mobile app
30th Apr 2022, 10:53 AM
Ketan Lalcheta
Ketan Lalcheta - avatar