我是Go语言的新手,想要在Go中创建和初始化一个结构体数组。我的代码如下:
type node struct {
name string
children map[string]int
}
cities:= []node{node{}}
for i := 0; i<47 ;i++ {
cities[i].name=strconv.Itoa(i)
cities[i].children=make(map[string]int)
}
我得到了以下错误:
panic: runtime error: index out of range
goroutine 1 [running]:
panic(0xa6800, 0xc42000a080)
请帮忙。TIA :)