一般情況下,定義結構體的時候是字段名與其類型一一對應,實際上Go支持只提供類型,而不寫字段名的方式,也就是匿名字段,也稱為嵌入字段。
~~~
//人
type Person struct {
name string
sex byte
age int
}
//學生
type Student struct {
Person // 匿名字段,那么默認Student就包含了Person的所有字段
id int
addr string
}
~~~