Create a deep copy of an array C++

后端 未结 4 889
迷失自我
迷失自我 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:21

    The strings also have dynamic memory, so you'd have to go through each string and make a copy of it.

    A fix would be copying each string inside of your array instead of memcopy. The exception is from two different strings having the same pointer to a piece of memory and both trying to free it.

提交回复
热议问题