golang结构体嵌套
package mainimport "fmt"
type Address struct {
city, state string
}
type Preson struct {
name string
age int
address Address
}
func main() {
var x Preson
x.name = "Naveen"
x.age = 50
x.address = Address{
city:"赤峰",
state: "中国",
}
fmt.Println("姓名", x.name)
fmt.Println("年龄", x.age)
fmt.Println("城市", x.address.city)
fmt.Println("国家", x.address.state)
}
页:
[1]