mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:06:41 +08:00
@@ -110,14 +110,14 @@ type A struct {a int}
|
||||
type B struct {a, b int}
|
||||
|
||||
type C struct {A; B}
|
||||
var c C;
|
||||
var c C
|
||||
```
|
||||
|
||||
规则 2:使用 `c.a` 是错误的,到底是 `c.A.a` 还是 `c.B.a` 呢?会导致编译器错误:**ambiguous DOT reference c.a disambiguate with either c.A.a or c.B.a**。
|
||||
|
||||
```go
|
||||
type D struct {B; b float32}
|
||||
var d D;
|
||||
var d D
|
||||
```
|
||||
|
||||
规则1:使用 `d.b` 是没问题的:它是 float32,而不是 `B` 的 `b`。如果想要内层的 `b` 可以通过 `d.B.b` 得到。
|
||||
|
Reference in New Issue
Block a user