package main
import "fmt"
type Base struct {
Name string
}
func (b *Base) SetName(name string) {
b.Name = name
}
func (b *Base) GetName() string {
return b.Name
}
type Child struct {
base Base
}
func (c *Child) GetName() string {
c.base.SetName("modify...")
return c.base.GetName()
}
type Child2 struct {
base *Base
}
type Child3 struct {
Base
}
type Child4 struct {
*Base
}
func main() {
c := new(Child)
c.base.SetName("world")
fmt.Println(c.GetName())
c2 := new(Child2)
c2.base = new(Base)
c2.base.SetName("ccc")
fmt.Println(c2.base.GetName())
c3 := new(Child3)
c3.SetName("1111")
fmt.Println(c3.GetName())
c4 := new(Child4)
c4.Base = new(Base)
c4.SetName("2222")
fmt.Println(c4.GetName())
}