Create a deep copy of an array C++

后端 未结 4 997
迷失自我
迷失自我 2021-01-28 00:44

I am try to solve some problems in my program and it would appear that there is either a problem with my copy constructor or with my destructor. I am getting a memory exception.

4条回答
  •  误落风尘
    2021-01-28 01:12

    That code doesn't make any sense. First you initialize your members to the values passed by the object to copy, through the initializer list. Then you allocate memory for the very same members and copy everything again.

    Most likely you are copying junk data into an uninitialized pointer. Get rid of the initializer list :readArray(a.readArray),arraysize(a.arraysize).

提交回复
热议问题