为了账号安全,请及时绑定邮箱和手机立即绑定

不能调用非函数撤回(类型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 关注
  • 197 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号