我正在使用 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(),
}
}
- 1 回答
- 0 關注
- 113 瀏覽
添加回答
舉報
0/150
提交
取消