Code:
type t_struct struct {
player string
id int
}
func main() {
dataA := make(map[string]t_struct)
dataB := make(map[string]*t_struct)
var playerA t_struct
playerA.player = "tom"
playerA.id = 1
dataA["classA"] = playerA
dataA["classA"].id = 2 // ERROR, why?
playerB := new(t_struct)
dataB["classB"] = playerB
dataB["classB"].player = "rick"
dataB["classB"].id = 3
}
And got error:
cannot assign to dataA["classA"].id
I wonder why dataA["classA"].id = 2
not worked but dataB["classB"].id = 3
did? Is it the only way to save struct pointer into map if you want to modify member value of it?