简体   繁体   English

go 中的 Clouser 错误“返回的 arguments 太多”

[英]Clouser error in go “too many arguments to return”

I am new to go and I am learning go from book "GO_DESIGN_PATTERN" I am new to go but I have decent experience in programming so that book consist of following code (I was on clousers topic)我是 go 的新手,我正在从“GO_DESIGN_PATTERN”一书中学习 go 我是 go 的新手,但我在编程方面有不错的经验

package main
func main(){
 addN := func(m int) {
     return func(n int){
        return m+n
     }
 }
 addFive := addN(5)
 result := addN(6)
 //5 + 6 must print 7
 println(result)
}

It is throwing following error它抛出以下错误

./prog.go:4:2: too many arguments to return
    have (func(int))
    want ()
./prog.go:5:2: too many arguments to return
    have (int)
    want ()
./prog.go:8:17: addN(5) used as value
./prog.go:9:16: addN(6) used as value

You must specify the type of return value.您必须指定返回值的类型。 func (a int) int {... return value} or func (a int) (b int) {... return} func (a int) int {... return value}func (a int) (b int) {... return}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM