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

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

不能調用非函數撤回(類型int)是什么意思?

不能調用非函數撤回(類型int)是什么意思?

Go
呼喚遠方 2022-08-24 20:22:53
我創建了這個程序package mainimport "fmt"var bankAccount = 12342func withdraw(withdrawAmnt int) int { //withdraw function, return int    bankAccount -= withdrawAmnt    if bankAccount < 0 {        bankAccount += withdrawAmnt //bankaccount cannot go negative        return 1    } else { return 0 }}func deposit(depositAmnt int) {    bankAccount += depositAmnt}func main() {    var choice int    var withdraw int    var deposit int    fmt.Printf("%d \n 1. withdraw \n 2. deposit \n 3. exit")    fmt.Scanln(&choice)    switch choice {        case 1:            fmt.Scanln(&withdraw)            if withdraw(withdraw) != 0 {                fmt.Println("Not succesful: not enough money (you're broke)")            }        case 2:            fmt.Scanln(&deposit)            deposit(deposit)        case 3:            os.Exit()    }}我不斷得到這個錯誤:不能調用非函數存款(類型int),也不能調用非功能存款(類型int)。
查看完整描述

2 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

它的意思正是它所說的:你不能調用一個非函數。只能調用函數。

這里:

            deposit(deposit)

您正在嘗試調用 ,但類型為:depositdepositint

    var deposit int

此變量聲明在包范圍內隱藏同名函數。deposit

若要解決您的問題,請為變量或函數使用其他名稱。


查看完整回答
反對 回復 2022-08-24
?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

變量名稱與函數名稱重疊。

嘗試更改其中之一


查看完整回答
反對 回復 2022-08-24
  • 2 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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