Go: go1.15.8 darwin/amd64
OS: MacOS 11.2.1

The program here <https://play.golang.org/p/rmnIexAGU-O> includes a type 
and a method that acts on that type:

type Prefix struct {
    prefix string
}

func (rec *Prefix) outputString(s string) {
    fmt.Printf("%v: %v\n", rec.prefix, s)
}

Very straightforward. I expected that this would work too:

type PrefixPtr *Prefix
func (rec PrefixPtr) outputString(s string) {
   fmt.Printf("%v: %v\n", rec.prefix, s)
}

But it led to:
# receiver
./receiver.go:24:6: invalid receiver type PrefixPtr (PrefixPtr is a pointer 
type)
./receiver.go:30:10: prefixer.outputString undefined (type PrefixPtr has no 
field or method outputString)

I understand that golfing doesn’t have implicit type conversions, and that 
PrefixPtr is not the same as *Prefix, so I guess what I’m asking is twofold:

   1. Why can’t receivers be a pointer type?
   2. Why isn’t *Prefix considered a pointer type?


-- 
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/a6763564-8c81-444d-8feb-03d5606db1ddn%40googlegroups.com.

Reply via email to