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
1 Resposta
+ 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;