为了账号安全,请及时绑定邮箱和手机立即绑定

不能在字段值中将(* struct)用作(* interface)

不能在字段值中将(* struct)用作(* interface)

Go
MYYA 2021-04-07 17:14:42
我有以下代码:// eventloop.gotype Object interface {    ActivateSlot(name string, parameters vector.Vector);}// main.goimport loop "./eventloop"// ...const slotname = "printer"type printer struct {    slot loop.Slot;}func (p *printer) Init() {    p.slot = loop.Slot{slotname, p}; // offending line}func (p *printer) ActivateSlot(name string, parameters vector.Vector) {    fmt.Println("Slot called: ", name); }当我尝试编译时,出现以下错误:jurily@jurily ~/workspace/go $ ./build.shmain.go:23: cannot use p (type *printer) as type *eventloop.Object in field value如果我将有问题的行注释掉,它可以编译并运行良好。这里发生了什么事?我想念什么?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 247 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号