Go语言 之指针类型匿名字段

package main

import (
    "fmt"
)

type Person02 struct {
    id   int
    name string
}

type Student02 struct {
    //指针类型
    *Person02
    score float64
}

func main() {
    var s Student02
    //取地址赋值
    s.Person02 = &Person02{1, "yy"}
    s.score = 90

    var s2 Student02 = Student02{&Person02{2, "yangs"}, 89}
    fmt.Println(s, s2)
}

 

posted @ 2019-06-29 10:04  样子2018  阅读(382)  评论(0编辑  收藏  举报