今天发现一个关于遍历的奇怪问题
我遍历修改数据后发现遍历修改的值全变成一样了 代码如下,有知道的大哥还请帮忙瞅瞅
下边是代码
```
package main
import "fmt"
type App struct {
AppAccount []*AppAccount
}
type AppAccount struct {
AppGroup []*AppGroup
}
type AppGroup struct {
Name string
}
func main() {
app := new(App)
account := new(AppAccount)
group := new(AppGroup)
account.AppGroup = append(account.AppGroup, group, group, group)
app.AppAccount = append(app.AppAccount, account, account, account)
x := 0
for _, appAccount := range app.AppAccount {
for _, appGroup := range appAccount.AppGroup {
appGroup.Name = fmt.Sprintf("--> %v", x)
x++
}
}
for _, appAccount := range app.AppAccount {
for _, appGroup := range appAccount.AppGroup {
fmt.Println(appGroup.Name)
}
}
}
```