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

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

Golang:嘗試刪除地圖中的項目時編譯錯誤

Golang:嘗試刪除地圖中的項目時編譯錯誤

Go
森林海 2022-10-10 10:31:08
我正在嘗試從 Golang 的地圖中刪除一個項目。這是代碼的粗略想法:import (    "github.com/aws/aws-sdk-go/aws/session")var sessions map[string]*session.Sessiontype config struct {    ...    endPoint string    ...}func newConfig() config {    var Config config = config{endPoint: "myEndpoint"}    return Config}func createSession(Config *config) error {    ...    sessions = make(map[string]*session.Session)    ...    session, err := session.NewSession( <session info here> )    sessions[Config.endPoint] = session    ...}func main() {    Config := newConfig()    err := createSession()    ...    if <some condition where i want to delete the session> {        delete(sessions, Config.endPoint)    }}但是我收到了這個編譯錯誤:# ./build_my_program.sh./myprogram.go:9998:12: cannot use sessions (type map[string]*session.Session) as type *config in argument to delete./myprogram.go:9999:29: cannot use Config.endPoint (type string) as type *session.Session in argument to delete我不明白這里的問題。唯一讓我懷疑的是在映射中使用指針作為類型。假設(shè)我需要保留指針類型,關(guān)于如何解決的任何想法?
查看完整描述

2 回答

?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

內(nèi)置函數(shù)在包中delete被遮蔽。func delete(*config, *session.Session) {}重命名包中的函數(shù)。



查看完整回答
反對 回復(fù) 2022-10-10
?
紅顏莎娜

TA貢獻1842條經(jīng)驗 獲得超13個贊

你在哪里定義了一個delete函數(shù)?


package main


func delete(a, b string) {

}


func main() {

    m := map[int]int{}

    m[1] = 1

    delete(m, 1)

}

./del.go:9:8: cannot use m (type map[int]int) as type string in argument to delete

./del.go:9:12: cannot use 1 (type untyped int) as type string in argument to delete



查看完整回答
反對 回復(fù) 2022-10-10
  • 2 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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