Defining golang struct function using pointer or not
Posted
by
Jacob
on Stack Overflow
See other posts from Stack Overflow
or by Jacob
Published on 2014-08-19T11:19:42Z
Indexed on
2014/08/22
22:21 UTC
Read the original article
Hit count: 246
go
Can someone explain to me why appending to an array works when you do this:
func (s *Sample) Append(name string) {
d := &Stuff{
name: name,
}
s.data = append(s.data, d)
}
But not when you do this:
func (s Sample) Append(name string) {
d := &Stuff{
name: name,
}
s.data = append(s.data, d)
}
Is there any reason at all why you would want to use the second example.
© Stack Overflow or respective owner