我想了解 Go 中的高阶函数。我有以下程序:package mainimport "fmt"func caller(foo func(string) string) { result := foo("David") fmt.Println(result)}bar := func(name string) string { return "Hello " + name}func main(){ caller(bar)}当我运行它时:去运行 higher_order_functions.go它给出了以下错误:# command-line-arguments./higher_order_functions.go:10:1: syntax error: non-declaration statement outside function body./higher_order_functions.go:11:5: syntax error: unexpected return, expecting )我期待输出:“你好大卫”
2 回答
- 2 回答
- 0 关注
- 85 浏览
添加回答
举报
0/150
提交
取消