package main

import "fmt"

type Person struct {
name string //名字
sex byte //性别
age int //年龄
} type Student struct {
Person //只有类型,没有名字,匿名字段,继承了Person的成员
id int
addr string
} func main() {
//顺序初始化
var s1 Student = Student{Person{"mike", 'm', }, , "北京"}
fmt.Println("s1 = ", s1) //自动推导类型
s2 := Student{Person{"mike", 'm', }, , "北京"}
//fmt.Println("s2 = ", s2)
//%+v, 显示更详细
fmt.Printf("s2 = %+v\n", s2) //指定成员初始化,没有初始化的常用自动赋值为0
s3 := Student{id: }
fmt.Printf("s3 = %+v\n", s3) s4 := Student{Person: Person{name: "mike"}, id: }
fmt.Printf("s4 = %+v\n", s4) //s5 := Student{"mike", 'm', 18, 1, "北京"} //err }
s1 =  {{mike  }  北京}
s2 = {Person:{name:mike sex: age:} id: addr:北京}
s3 = {Person:{name: sex: age:} id: addr:}
s4 = {Person:{name:mike sex: age:} id: addr:}
05-12 23:13