I feel confused when I use the function pointer which point to the struct method. Here is the test code:
/*** package main type Zoo struct { Animal string } func (z Zoo) Display(){ fmt.Printf("Current animal is:%s\n", z.Animal) } func main(){ gz := &Zoo{ Animal: "Monkey", } pf := gz.Display pf() //display "Current animal is Monkey" gz.Animal="Tiger" pf() //display "Current animal is Monkey" gz.Display() //display "Current animal is Tiger" } ***/ As the code is shown above, even though I changed the value of the member field of the Zoo instance gz, the function pointer call that followed still prints the unmodified value. Can someone help explain why? In my opinion, The function pointer pf should bind to the instance gz and its method(note that gz here is a pointer variable), if so anytime I change the value of the variable gz, pf should reflect the changes. Thanks, Ethan -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/60c6523c-dbce-4530-aa51-06f2c1223ca8n%40googlegroups.com.