【问题标题】:How to handle map[string]*struct inside struct?如何处理结构内的 map[string]*struct?
【发布时间】: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)

标签: go pointers struct


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-08
  • 2021-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多