0
は私が新しいキーパーを作成して、次の(を呼び出すときに、私はゴー関数ポインタの問題
func(l keeper) next() {
l.ptr++
}
それに機能を追加します。しかし、構造体
type keeper struct {
ptr int32
}
を持っている)
tester := keeper {
ptr: 0,
}
test.next()
私はテスター内のptr値を変更していないようです。関数をポインタに変更すると、それは動作します。
func(l *keeper) next() {
l.ptr++
}
なぜそうですか?
別の関連するQ&Aを参照してください:[https://stackoverflow.com/questions/27775376/value-receiver-vs-pointer-receiver-in-golang](https://stackoverflow.com/questions/27775376/value- receiver-vs-pointer-receiver-in-golang) – putu