Hi,
I am a newcomer for Go and I`m studying the offical tour of Go. I have some question on this tour
A Tour of Go complete code are at the bottom.
when I change the receiver of
func (p Person) String() string
to
func (p *Person) String() string
it doesnt print the string returned by String method.
it seems like the String method didnt be called within the fmt.Println() call.
Any help would be appreciated. thanks very much!
package main
import "fmt"
type Person struct {
Name string
Age int
}
func (p Person) String() string {
return fmt.Sprintf("%v (%v years)", p.Name, p.Age)
}
func main() {
a := Person{"Arthur Dent", 42}
z := Person{"Zaphod Beeblebrox", 9001}
fmt.Println(a, z)
}