亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不能在字段值中將(* 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 關注
  • 246 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號