【发布时间】:2022-06-16 15:20:42
【问题描述】:
我有类型的结构
type Trie struct {
node map[string]*Trie
wordEnd bool
}
我是这样声明的,但是出现了错误
func main() {
a := new(Trie)
a.node = make(map[string]Trie) //Tried using &Trie too and obviously it did not work
}
错误
cannot use make(map[string]Trie) (value of type map[string]Trie) as type map[string]*Trie in assignment
如何申报?我使用指针作为映射值的原因是因为要将结构放入相同类型的结构中,您必须使用结构的指针。
【问题讨论】:
-
make(map[string]*Trie)