package main
import "fmt"
func main() {
items := make([]map[int]int, 5)
for i := range items {
items[i] = make(map[int]int, 1)
items[i][i] = 2
}
fmt.Printf(" Value of items: %v\n", items)
items2 := make([]map[int]int, 5)
for _, item := range items2 {
item = make(map[int]int, 1)//只是获得拷贝
item[1] = 2
}
fmt.Printf(" Value of items: %v\n", items2)
}
原文地址:https://www.cnblogs.com/swtczb/p/11632639.html
时间: 2024-11-19 13:49:44