将值赋给父golang结构字段

将值赋给父golang结构字段,go,Go,有两种情况: type A struct { A_FIELD string } type B struct { A B_FIELD string } func main() { b := &B{ A_FIELD: "aaaa_field", B_FIELD: "bbbb_field", } } 及 为什么第二个有效,而第一个无效?我收到编译时异常。我应该如何改变第一个工作 为什么第二个有效,而第一个无效 因

有两种情况:

type A struct {
    A_FIELD  string
}
type B struct {
    A
    B_FIELD  string
}

func main() {
    b := &B{
        A_FIELD: "aaaa_field",
        B_FIELD: "bbbb_field",
    } 
}

为什么第二个有效,而第一个无效?我收到编译时异常。我应该如何改变第一个工作

为什么第二个有效,而第一个无效

因为

b.A_FIELD = "aaaa_field"
实际上是

b.A.A_FIELD = "aaaa_field"
乔装打扮

我应该如何改变第一个工作

你应该积极阅读

为什么第二个有效,而第一个无效

因为

b.A_FIELD = "aaaa_field"
实际上是

b.A.A_FIELD = "aaaa_field"
乔装打扮

我应该如何改变第一个工作

你应该积极阅读