Error "X does not implement Y (method has a pointer receiver)" in Go
Hi everyone! I just started learning Go and encountered an error I can't understand. I have an interface and a struct that I think implements it. But the compiler says it doesn't.
Here's my code:
```go
package main
import "fmt"
type Greeter interface {
Greet() string
}
type Person struct {
Name string
}
func (p *Person) Greet() string {
return "Hello, " + p.Name
}
func sayHello(g Greeter) {
fmt.Println(g.Greet())
}
func main() {
p := Person{Name: "Alice"}
sayHello(p) // Error: Person does not implement Greeter (method Greet has pointer receiver)
}
```
Error: `Person does not implement Greeter (method Greet has pointer receiver)`. I understand that the `Greet()` method is defined on the pointer `*Person`, not on `Person`. But