package main
import "fmt"
type intr interface {
String() string
}
type bar struct{}
func (b *bar) String() string {
return "bar"
}
type foo struct {
bar *intr
}
func main() {
bar1 := bar{}
foo1 := foo{bar: &bar1}
fmt.Println(foo1)
}
我得到一个编译时错误:
不能在字段值中使用 &bar1 (type *bar) 作为 *intr 类型:*intr 是指向接口的指针,而不是接口
为什么会发生这个错误?如何分配foo.bar?
UYOU
紫衣仙女
相关分类