第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Golang - 通過接口獲取指向結(jié)構(gòu)字段的指針

Golang - 通過接口獲取指向結(jié)構(gòu)字段的指針

Go
三國紛爭 2021-07-12 17:35:21
我還處于理解 Go 接口的早期階段。我正在編寫一些邏輯模擬,并具有類似以下代碼的內(nèi)容(我在這里進行了大量簡化):請參閱我的問題的評論:type LogicNode struct {    Input   *bool    Output   *bool    Operator string    Next     Node}func (n *LogicNode) Run() {    // do some stuff here    n.Next.Run()}type Node interface {    Run()}func main() {    nodes := make([]Node, 1000)    for i := 0; i < 1000; i++ {        n := LogicNode{            //assign values etc.        }        nodes[i] = &n    }    for i, node := range nodes {        // I need to access LogicNode's Output pointer here, as a *bool.        // so I can set the same address to other Node's Input thereby "connecting" them.        // but I could only get something like this:        x := reflect.ValueOf(node).Elem().FieldByName("Output")        // which is <*bool Value>        // I couldn't find a way to set a new *bool to the underlying (LogicNode) Struct's Input or Output..    }}我使用接口的原因是因為還有其他節(jié)點類型 FloatNode MathNode 等,它們具有不同的字段,但它們實現(xiàn)了自己的 run 方法。我已經(jīng)成功地使用了 Value 的 SetString 或 SetBool 方法,但無法在那里設(shè)置指針......提前致謝。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 249 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號