package main
import "fmt"
type Test struct {
a string
}
func (t *Test)Error() string{
return t.a
}
func main() {
test1 := new(Test)
test1.a = "oops"
p := *test1
hasError(p)
}
func hasError (e error){
fmt.Printf("%s",e.Error())
}
我想要 把这个类型声明为error类型的时候就会出错
cannot use *test1 (type Test) as type error in argument to hasError:
Test does not implement error (Error method has pointer receiver)
应该传值 ,传指针是不不行的