duanjinchi1982 2014-08-22 20:40
浏览 1164
已采纳

如何解决Golang中“返回的参数过多”的问题?

In a print function I am writing, I am trying to return a value based on the result of a switch statement; however, I am getting the error too many arguments to return.

Forgive me if this question has a simple answer, but shouldn't it not matter how many arguments a function has and it can return just one thing? Or does it need to return one thing for each argument.

Here is my code. I am getting an error on the return line ( Too many arguments to return ). How can I fix it so that it returns the string set in the switch statement?

package bay

func Print(DATA []TD, include string, exclude []string, str string) {
    result := NBC(DATA, include, exclude, str)
    var sentAnal string
    switch result {
    case 1:
        sentAnal = "Strongly Negative"
    case 2:
        sentAnal = "Very Negative"
    case 3:
        sentAnal = "Negative"
    case 4:
        sentAnal = "Little Negative"
    case 5:
        sentAnal = "Neurtral"
    case 6:
        sentAnal = "Little Positive"
    case 7:
        sentAnal = "Positive"
    case 8:
        sentAnal = "More Positive"
    case 9:
        sentAnal = "Very Positive"
    case 10:
        sentAnal = "Strongly Positive"
    default:
        sentAnal = "Unknown"
    }
    return sentAnal
}
  • 写回答

2条回答 默认 最新

  • dongshukou0240 2014-08-22 20:44
    关注

    You need to specify what you will return after specifying the input parameters, this is not python.

    This:

    func Print(DATA []TD, include string, exclude []string, str string) {
    

    Should be:

    func Print(DATA []TD, include string, exclude []string, str string) string {
    

    Recommended reads:

    Or even all of effective go

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题