An Introduction To Programming In Go 读书笔记
-- 9 Structs and Interfaces - Embedded Types
packagemain import"fmt" typePersonstruct{ Namestring } typeAndroidstruct{ Person//直接嵌入亦可使用自定义名称如OwnerPerson Modelstring } func(p*Person)talk(){ fmt.Println("hi,I'm",p.Name) } func(a*Android)sayhi(){ a.Person.talk()//不冲突时亦可直接使用a.talk() fmt.Println("--from",a.Model) } funcmain(){ a:=new(Android) a.Person.Name="John"//不冲突时亦可直接使用a.Name a.Model="iphone" a.sayhi() }