修改map结构体成员的问题
值类型数据传地址的修改方法
func change(isT *bool) { *isT = true } func TestChange(t *testing.T) { isT := false change(&isT) fmt.Println("isT: ", isT) // true }
引用类型的数据
type Student struct { Name string Score float64 } func changeStudent(stu *Student, newName string, newScore float64) { stu.Name = newName stu.Score = newScore } func TestChangeStudent(t *testing.T) { s1 := Student{ Name: "whw", Score: 99, } changeStudent(&s1, "naruto", 100) fmt.Println("s1: ", s1) // s1: {naruto 100} }
~~~