我只是在研究 Go tour,我对指针和接口感到困惑。为什么这个 Go 代码不能编译?
package main
type Interface interface {}
type Struct struct {}
func main() {
var ps *Struct
var pi *Interface
pi = ps
_, _ = pi, ps
}
也就是说,如果 Struct
是 Interface
,为什么 *Struct
不是 *Interface
呢?
我得到的错误消息是:
prog.go:10: cannot use ps (type *Struct) as type *Interface in assignment:
*Interface is pointer to interface, not interface