1 如果map的value是struct,则需要是指针类型,否则的话不能对结构体的某个字段单调赋值,只能整体赋值,因为map扩容的时候要变址

package main
import "fmt"

type person struct {
    name string
    age  int
    sex  string
}
func main() {
    s := make(map[int]*person)
    s[1] = &person{"tony", 20, "man"}
    fmt.Println(s[1])
    s[1].name = "tom"
    fmt.Println(s[1].name)
}
View Code

相关文章:

  • 2021-07-15
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2021-09-28
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案