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