通过编译代码很容易得到答案:
prog.go:19: invalid receiver type Vegetable (Vegetable is a pointer type)
该错误是基于以下规格要求:
接收器类型必须采用T或 T的形式,其中T是类型名称。用T表示的类型称为接收方基本类型; 它不能是指针或接口类型*
,并且必须在与方法相同的包中声明。
(强调我的)
声明:
type Vegetable *vegetable_s
声明一个 指针 类型,即
Vegetable没有资格作为方法接收者。



