The copy constructor creates dependent copy

前端 未结 5 1130
盖世英雄少女心
盖世英雄少女心 2021-01-23 16:34

I implemented the copy constructor as it is described here. But still the problem is that when I update route_copy, then the same update is applied to route

5条回答
  •  再見小時候
    2021-01-23 17:13

    what you do with the copy constructor is just make the new Route use the list of the old Route and therefor any change to one of them immediately effect the other

    what you need to do is make the copy constructor make a new list:

    sites = new ArrayList(oldList);
    

提交回复
热议问题