ret
This commit is contained in:
parent
204c4c783f
commit
8aceabf0f1
|
|
@ -2,18 +2,19 @@ package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func square() func () int {
|
type Point struct {
|
||||||
var x int
|
x int
|
||||||
return func() int {
|
|
||||||
x++
|
|
||||||
return x*x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Point) Inc() {
|
||||||
|
p.x++
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
f := square()
|
points := []*Point{{1},{2},{3}}
|
||||||
fmt.Println(f())
|
|
||||||
fmt.Println(f())
|
for _,p := range points {
|
||||||
fmt.Println(f())
|
p.Inc()
|
||||||
fmt.Println(f())
|
}
|
||||||
fmt.Println(f())
|
fmt.Println(points[0].x)
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user