// 结构
package main
import "fmt"
// 定义一个结构
type person struct {
Name string
Age int
Content struct {
Phone string
City string
}
}
// 继承一个结构
type student struct {
person
Sex string
}
func main() {
// 可以不使用&,但推荐使用,方便引用传递
a := &student{}
a.person.Name = "说易事"
a.person.Age = 26
a.person.Content.City = "南宁"
a.person.Content.Phone = "10086"
a.Sex = "男"
fmt.Println(a)
b := &student{person:person{Name:"老鹰开灰机", Age: 24}}
fmt.Println(b)
}输出:
&{{说易事 26 {10086 南宁}} 男}
&{{老鹰开灰机 24 { }} }