结构体Dog实现了接口的所有方法Animal,为什么*Dos不能赋值给*Animal?
type Animal interface {
run()
}
type Dog struct {
name string
}
func (d *Dog) run() {
fmt.Println( d.name , " is running")
}
func main(){
var d *Dog
var a *Animal
d = new(Dog)
d.run()
a = d //errors here
}
Go 通知以下错误:
Cannot use 'd' (type *Dog) as type *Animal in assignment
MMTTMM
30秒到达战场
萧十郎
相关分类