我期待看到3,發生了什麼?遞增結構變量
package main
import "fmt"
type Counter struct {
count int
}
func (self Counter) currentValue() int {
return self.count
}
func (self Counter) increment() {
self.count++
}
func main() {
counter := Counter{1}
counter.increment()
counter.increment()
fmt.Printf("current value %d", counter.currentValue())
}
http://play.golang.org/p/r3csfrD53A
差不多http://stackoverflow.com/questions/16540481/why-is-this-struct-not-working – nemo