嗨,我是新来的,并试图弄清楚地图如何工作。 我已经编写了一个小测试程序,似乎无法让它工作。 我做错了什么?嵌套地图结构golang
package main
import (
"fmt"
)
type Stats struct {
cnt int
category map[string]Events
}
type Events struct {
cnt int
event map[string]Event
}
type Event struct {
value int64
}
func main() {
stats := new(Stats)
stats.cnt = 33
stats.category["aa"].cnt = 66
stats.category["aa"].event["bb"].value = 99
fmt.Println(stats.cnt, stats.category["aa"].event["bb"].value)
}
'stats.category [ “AA”]'应该是地图上的字符串切换到事件片段,但您正在尝试将其赋值为66. – verygoodsoftwarenotvirus