mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 07:02:11 +08:00
35 lines
616 B
Go
35 lines
616 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type innerS struct {
|
|
in1 int
|
|
in2 int
|
|
}
|
|
|
|
type outerS struct {
|
|
b int
|
|
c float32
|
|
int // anonymous field
|
|
innerS // anonymous field
|
|
}
|
|
|
|
func main() {
|
|
outer := new(outerS)
|
|
outer.b = 6
|
|
outer.c = 7.5
|
|
outer.int = 60
|
|
outer.in1 = 5
|
|
outer.in2 = 10
|
|
|
|
fmt.Printf("outer.b is: %d\n", outer.b)
|
|
fmt.Printf("outer.c is: %f\n", outer.c)
|
|
fmt.Printf("outer.int is: %d\n", outer.int)
|
|
fmt.Printf("outer.in1 is: %d\n", outer.in1)
|
|
fmt.Printf("outer.in2 is: %d\n", outer.in2)
|
|
// with a struct-literal:
|
|
outer2 := outerS{6, 7.5, 60, innerS{5, 10}}
|
|
fmt.Println("outer2 is: ", outer2)
|
|
|
|
}
|