经典坑
for _,stu := range stus {
m[stu.name] = &stu
}
&stu一直指向stu这个变量,而在for循环里面,stu变量只有一个,所以m里存的都是同一个地址
对比c++,这种写法存储了for scope里的临时变量的地址,结果是未知的
go里虽然有垃圾回收,但这种写法也不安全
【 在 nic411 (难得糊涂) 的大作中提到: 】
: type student struct {
: name string
: age int
: ...................
--
FROM 106.120.46.*