```go
type Girl struct {
name string
}
func (g *Girl) Appointment() {
fmt.Println("I appointment ",g.name)
}
func main(){
friends := []Girl{{"Juliet"},{"Emily"},{"Amy"}}
for _,friend := range friends{
defer friend.Appointment()
}
/*
打印结果:
I appointment Amy
I appointment Amy
I appointment Amy
*/
for _,friend := range friends{
f := friend
defer f.Appointment()
}
/*
打印结果:
I appointment Amy
I appointment Emily
I appointment Juliet
*/
}
```
有疑问加站长微信联系(非本文作者)