go语言初始化内部结构体3中方式
1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 type User struct { 8 Id int 9 Name string 10 Age int 11 } 12 13 type Manger struct { 14 User 15 title string 16 } 17 18 func main() { 19 m := Manger{User:User{1, "ok", 12}, title:"123"} //可以 20 m2 := Manger{User{1, "ok", 12}, "123"} //可以 21 m3 := Manger{User:User{Id:1, Name:"ok", Age:12}, title:"123"} //可以 22 23 fmt.Println(m) 24 fmt.Println(m2) 25 fmt.Println(m3) 26 27 }