开发者社区> 问答> 正文

go程序运行报错cannot use []int literal (type []int)

代码如下

package main

import "fmt"

func split(sum ...int)int {
	s:=0
	for _,item := range sum {
		s+=item
	}
	return s
}

func main() {
	fmt.Println(split([]int{1,2,3,4}))
}

运行结果

# command-line-arguments
./he.go:14:25: cannot use []int literal (type []int) as type int in argument to split

展开
收起
睡着了去做梦 2021-10-21 14:07:53 1573 0
1 条回答
写回答
取消 提交回答
  • split参数类型不对应,应该用split(arr []int)

    2021-10-22 10:29:11
    赞同 展开评论 打赏
问答分类:
Go
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Go语言路上踩过的坑 立即下载
gohbase :HBase go客户端 立即下载
Go构建日请求千亿级微服务实践 立即下载

相关实验场景

更多