Element not being removed from list.List

Viewed 41

If I execute the code below, the element in the list doesn't get removed. I'm pretty sure its because somehow there is a deep copy of the list being created inside Create(). If I change the return of Create from ListWrapper to *ListWrapper the code works.

Still its not intuitive for me why it wouldn't work with the copy. Can anyone shed any light on this? Appreciate the help.

type ListWrapper struct {
    Value list.List
}

func Create() ListWrapper {
    var lw ListWrapper
    lw.Value.PushBack(1)
    return lw
}

func main() {
    lw := Create()
    lw.Value.Remove(lw.Value.Back())
}
1 Answers
Related