追加到结构数组和结构的结构数组之间有什么区别

时间:2019-01-02 23:10:39

标签: struct

go.lang的新手,我进行了搜索,这两个(人/人)有什么区别?

type Person struct {
    Name string
    Age  int
}
type People []struct {
    Person
}

func main() {
    person := Person{Name: "a", Age: 1}

    var people People
    people = append(people, person)
    // throws: cannot use person (type Person) as type struct { Person } in append

    var peoples []Person
    peoples = append(peoples, person)
}

0 个答案:

没有答案