0

Issue in move constructor

Hi Can anyone help me understand issue with below code ? It is run time error occurred when I am moving object. https://code.sololearn.com/c3Vs4rhwjyDL/?ref=app

26th Feb 2022, 4:35 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Réponse
+ 3
Considering that `pdata` is uninitialized in the move constructor, the loop for (int i = 0;i<size;++i) pdata[i] = obj.pdata[i]; invokes undefined behaviour as you are writing into undefined memory. For a move constructor, simply copying the pointer instead of the elements would make more sense: pdata = obj.pdata;
26th Feb 2022, 1:15 PM
Shadow
Shadow - avatar