我只是在处理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
https://stackoverflow.com/questions/13511203
复制相似问题