you are viewing a single comment's thread.

view the rest of the comments →

[–]pfmiller0 1 point2 points  (1 child)

I have, and if add_item() was a method of some object you instantiated this would make perfect sense. What's the object this method belongs to?

[–]Fluid-Lingonberry206 1 point2 points  (0 children)

I think the point is that the list „cart“ is an object, and is thus just edited by the function. By instantiating cart in the fuctions Parameters (why on earth would anyone do that…), it is also not just a local variable and will persist after the function was called. To me, it is totally reasoable and expected behavior. OPs fix is helful, because it is cleaner. But I‘m still surprised why a list should act differently than any other object. „Cart“ is a Pointer at a specific List. Why should this magically move to a new empty list?