package main
import "fmt"
type Hoge struct {
m string
}
type Fuga struct {
Hoge
}
func main() {
h := Hoge{"hogehoge"}
f := Fuga{Hoge: h}
fmt.Println(f)
}
実行結果
{{hogehoge}}
FugaはHoge->mを直下のメンバーのように呼び出せるけど実際は入れ子の状態で格納されている
fmt.Println(f.m) // out: "hogehoge"
fmt.Println(f.Hoge.m) // out: "hogehoge"
よって構造違うのでキャストもできない
f := Fuga(h) // compile error
最近知った。以上。