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

如何解决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条)

报告相同问题?

悬赏问题

  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误