Skip to content

Instantly share code, notes, and snippets.

@aliok
Created February 21, 2020 11:20
Show Gist options
  • Save aliok/10e57a3b51c6f399029eef7d04572fa0 to your computer and use it in GitHub Desktop.
Save aliok/10e57a3b51c6f399029eef7d04572fa0 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type C struct {
x int
}
type B struct {
c C
}
type A struct {
b B
}
func main() {
c := C{1}
b := B{c}
a := A{b}
fmt.Printf("%v %v %v \n", a, b, c)
c.x = 100
fmt.Printf("%v %v %v \n", a, b, c)
b.c.x = 200
fmt.Printf("%v %v %v \n", a, b, c)
update01(&a)
fmt.Printf("%v %v %v \n", a, b, c)
update02(&b)
fmt.Printf("%v %v %v \n", a, b, c)
update02(&a.b)
fmt.Printf("%v %v %v \n", a, b, c)
update03(&c)
fmt.Printf("%v %v %v \n", a, b, c)
update03(&a.b.c)
fmt.Printf("%v %v %v \n", a, b, c)
}
func update01(a *A){
a.b.c.x = 2
}
func update02(b *B){
b.c.x = 3
}
func update03(c *C){
c.x = 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment