make(type,len,cap)make(type,len)
players := make([]*Player,1)
这样就相当于初始化了一个如下的切片。
players = []*Player{nil}
如果添加一个数据
players = append(players,NewPlayer("小王"))
则会在nil后面附加上这个NewPlayer(“小王”)
players = []*Player{nil,&Player{name:"小王"}}
当需要遍历这个players切片,去调用具体函数时,此时由于players第一个元素为初始化的nil,用它调用函数则会出现空指针
for _,p := range players {
p.DoSomeThing()
}