我只是在Go导游中工作,我对指针和接口感到困惑。为什么此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
慕尼黑的夜晚无繁华
相关分类