Go 语言复制指针的值可以通过 *copy = *pointer
完成。
1package main
2
3import "fmt"
4
5type person struct {
6 name string
7 gender int
8}
9
10func main() {
11 foo := &person{"foo", 1}
12 bar := &person{}
13 *bar = *foo
14 fmt.Println(foo, bar)
15
16 bar.name = "bar"
17 fmt.Println(foo, bar)
18}
1$ go run main.go
2&{foo 1} &{foo 1}
3&{foo 1} &{bar 1}