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
}
func (c *Child2) GetName() string {
c.base.SetName("canuser?")
return c.base.GetName()
}
func main() {
c := new(Child)
c.base.SetName("world")
fmt.Println(c.GetName())
c2 := new(Child2)
c2.base = new(Base)
fmt.Println(c2.GetName())
}