函数调用中的"用作值"

Saa*_*aad 104 go

在条件语句中评估函数时,调用函数的正确方法是什么?

package main
import "fmt"
func main(){
        if sumThis(1,2) > sumThis(3,4){
                fmt.Println("test")
        } else {
                fmt.Println("derp")
        }
}
func sumThis(a, b int){
        return a+b
}
Run Code Online (Sandbox Code Playgroud)

这会返回错误:

./test4.go:4: sumThis(1, 2) used as value
./test4.go:4: sumThis(3, 4) used as value
./test4.go:11: too many arguments to return
Run Code Online (Sandbox Code Playgroud)

你怎么用Go写的?

Mac*_*iej 149

你忘了申报一个返回值.它应该是:

func sumThis(a, b int) int {
// ...
Run Code Online (Sandbox Code Playgroud)