package main
import "fmt"
type good struct {
id int64
sum int64
}
func main() {
good1 := good{1, 3}
good2 := good{1, 3}
good := []good{}
good = append(good, good1, good2)
for _, v := range good {
//修改值(无效)
v.sum = 7
}
fmt.Println(good)
for i, v := range good {
fmt.Println(v)
//修改值成功
good[i].sum = 7
}
fmt.Println(good)
}
原文:https://www.cnblogs.com/niuben/p/14437511.html