type Parent struct{}
func (p *Parent) A() {
p.B()
}
func (p *Parent) B() {
fmt.Println("parent.B()")
}
type Child struct {
Parent
}
func (c *Child) B() {
fmt.Println("child.B()")
}
定义了两个结构体,Parent 和 Child
Parent 有 A()和 B()两个方法,在 A 中调用了 B
Child 只实现了 B(),然后按如下方式调用:
func main() {
p := &Parent{}
c := &Child{}
p.A()
c.A()
c.Parent.A()
}
发现 c.A()和 c.Parent.A()都只调用到了 Parent 的 B()方法
有办法可以在 A()方法中调用到 Child 的 B()方法吗