// code by shaoyongyang package main import ( "fmt" ) type People struct { name string age int weight int } type Student struct { People specialty string } func main() { liming := Student{People{"liming", 18, 183}, "None Specialty"} fmt.Println(liming.name) liming.People.name = "xiaohong" fmt.Println(liming.name) }
其实就是一个结构体,嵌入了另一个结构体。 对应的修改数据方式方式,以及数据访问的方式跟着改变。
时间: 2024-10-15 10:25:22