我正在尝试创建一个结构数组并在其中启动一些数据。
结构:
type Person struct{
id int
enlighten bool
channel chan int
}
作业:
table := make([]Philospher, numPhil)
for i :=0; i < 5; i++{
p := Philospher{
id: i,
enlighten: false,
channel: make(chan int),
}
table = append(table, p)
}
for j :=0; j < 5; j++{
fmt.Println(table[j].id);
}
以下是上述代码的输出:
0
0
0
0
0
我想弄清楚为什么不是
0
1
2
3
4
我也试过&在Philospher前面用add,还是一样的
慕容森
临摹微笑
桃花长相依
随时随地看视频慕课网APP
相关分类