Create a deep copy of an array C++

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

    I would not advice you to copy strings the way you do. As the string holds reference to heap memory you in fact copy the pointers and so the strings in both arrays are sharing memory. This is not very c++-ish and quite dangerous. I would advice you to use the assignment operator or copy constructors for the strings(yes do a cycle).

提交回复
热议问题