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

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

使用 Go 的堆棧集合聲明堆棧時遇到問題

使用 Go 的堆棧集合聲明堆棧時遇到問題

Go
MMTTMM 2023-07-10 15:04:19
我正在使用 VS Code 將最初用 C++ 編寫的工具轉換為 Go,但 Go linter 不喜歡我的堆棧聲明。我已經根據 Go 文檔導入了堆棧集合,并且我認為我的 go 工作區目錄層次結構是正確的。-go (workspace)    -bin    -pkg        -darwin_amd64            -github.com                -golang-collections                    -collections                        -stack.a    -src        -github.com            -golang-collections                -collections                    -stack                        stack.go                        stack_test.go            -zwnewsom                -verifier                   main.gopackage mainimport (    "C"    "github.com/golang-collections/collections/stack")type Item struct {    key   int    value int    //sum   int    sum float64    numerator   int64    denominator int64    exponent float64    status Status    promoteItems := stack.New()}'New()' 函數應該返回一個指向堆棧的指針,但 VS Code Go linter 在 ':= stack.New()' 下顯示黃色波浪線,并顯示錯誤“預期 ';',發現 ':=' “這是雙重令人困惑的,因為我的印象是 Go 不使用分號來終止行。
查看完整描述

1 回答

?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

不要初始化結構定義中的值,只需設置類型。創建結構體的新實例時初始化該值。


type Item struct {

    key   int

    value int

    //sum   int

    sum float64


    numerator   int64

    denominator int64


    exponent float64


    status Status


    promoteItems stack.Stack

}


func main() {

    // create an instance of struct Item

    item := Item{

        promoteItems: stack.New(),

    }

}


查看完整回答
反對 回復 2023-07-10
  • 1 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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