Golang回调函数问题:传递square函数时报错'function body missing'如何解决
Golang回调函数问题:传递square函数时报错’function body missing’如何解决
package main
import "fmt"
func main() {
fmt.Println(squareMinusNum(square, 8))
}
func square (int num) int {
return num*num
}
func squareMinusNum (f(int num) int, num int) int{
x:= f(num)-num
return x
}
更多关于Golang回调函数问题:传递square函数时报错'function body missing'如何解决的实战教程也可以访问 https://www.itying.com/category-94-b0.html
2 回复
你好 Sajir!
你只需要进行几个简单的修正。在 Go 语言中,类型是放在变量名后面的,例如 func(num int) 而不是 func(int num),你之前写的是后者。
https://play.golang.org/p/XexKFyWeL6l
如果对此还有任何疑问,请随时告诉我。
更多关于Golang回调函数问题:传递square函数时报错'function body missing'如何解决的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


