拷贝
package main
import "fmt"
type TestCopy struct {
a uint64
}
func (n *TestCopy) copy() *TestCopy {
copy := *n
return ©
}
func main() {
var n TestCopy
n.a = 10
cn := n.copy()
fmt.Println(cn.a)
cn.a = 20
fmt.Println(cn.a)
fmt.Println(n.a)
}
运行结果:
10
20
10