-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.go
More file actions
70 lines (56 loc) · 688 Bytes
/
test.go
File metadata and controls
70 lines (56 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import "fmt"
type X struct {
n int
}
type Y struct {
n int
}
func (x *X) Inc() {
x.n += 1
}
func (y Y) Inc() {
y.n += 1
}
type Combi struct {
a *X
b X
}
func (c *Combi) IncA() {
c.a.Inc()
c.b.Inc()
}
func (c Combi) IncB() {
c.a.Inc()
c.b.Inc()
}
func main() {
a := X{}
b := &X{}
e := a
f := b
c := Y{}
d := &Y{}
a.Inc()
b.Inc()
c.Inc()
d.Inc()
fmt.Println(a, b, c, d, e, f)
g := Combi{&X{}, X{}}
h := &Combi{&X{}, X{}}
r := g.a
s := g.b
t := h.a
u := h.b
g.a.Inc()
g.b.Inc()
h.a.Inc()
h.b.Inc()
fmt.Println(g, h, r, s, t, u)
g.IncA()
h.IncA()
fmt.Println(g, h, r, s, t, u)
g.IncB()
h.IncB()
fmt.Println(g, h, r, s, t, u)
}