type Person struct {
id int
name string
age int
}
type Student struct {
Person // 匿名字段实现继承关系
// *Person //指针作为匿名字段
class string
score int
}
func main() {
var stu Student
//需要对指针创建空间
//stu.Person = new(Person)
stu.id = 99
stu.age = 11
stu.name = "sd"
stu.class = "yi"
stu.score = 22
fmt.Println(stu)
}
网友评论