kod aşağıdakilere sahip arayüz için herhangi bir değer ayarlamak için:Nasıl {}
package main
import (
"fmt"
)
type Point struct {
x,y int
}
func decode(value interface{}) {
fmt.Println(value) // -> &{0,0}
// This is simplified example, instead of value of Point type, there
// can be value of any type.
value = &Point{10,10}
}
func main() {
var p = new(Point)
decode(p)
fmt.Printf("x=%d, y=%d", p.x, p.y) // -> x=0, y=0, expected x=10, y=10
}
Ben decode
işleve iletilen değerin, her türden değeri ayarlamak istiyorum. Go'da mümkün mü, yoksa bir şeyi yanlış anladım mı?
http://play.golang.org/p/AjZHW54vEa
Git pass-değeriyle . Yerel bir değişkene bir şey atamak asla dışarıyı etkilemez. Durumu paylaşmak için işaret ettiği şeyi değiştirmek için bir referans türünü (işaretçi gibi) kullanabilirsiniz; ama sonra işaret ettiği şeylere bir şey atamanız için doğru tipte bir işaretçiye ihtiyaç duyacaktır. – newacct