2018-03-28 9:39 GMT-07:00 Devon H. O'Dell <[email protected]>:
> CopyExplicitDeref gets a pointer to the struct in its receiver. If you
> have a pointer to T, then taking a pointer to the dereferenced T is a
> no-op: you get the pointer of the thing you just dereferenced. Any
> statement &*whatever will always yield the value of whatever. Copy
> happens on assignment, and no assignment occurs in this statement.
I just realized that one additional thing that might be confusing is
that you're expecting CopyExplicitDeref to get a copy of _something_
since everything in Go is done by-value. Indeed, CopyExplicitDeref
does get a copy of something: the pointer to T. So if you change
CopyExplicitDeref to:
func (t *T) CopyExplicitDeref() **T {
return &t
}
and in main:
a := &T{0}
b := a.CopyExplicitDeref()
fmt.Println(&a == b)
you will see that it's actually the pointer that is copied.
--dho
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.