看看这个沙盒
当声明一个从另一个结构体继承的结构体时:
type Base struct {
a string
b string
}
type Something struct {
Base
c string
}
然后调用指定继承值的函数会导致编译错误:
f(Something{
a: "letter a",
c: "letter c",
})
错误信息为:在结构体字面量中未知的 Something 字段 'a'
。
这对我来说似乎非常奇怪。这真的是预期的功能吗?
谢谢帮助!