您的位置:首页 > 编程语言 > Go语言

learn go function callback

2015-11-22 18:04 357 查看
package main

// 参考文档:
//     https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/06.7.md 
import (
"fmt"
)

func main () {
callback(1, Add)
}

func Add(a, b int) {
fmt.Printf("The sum of %d and %d is: %d\n", a, b, a+b);
}

func callback(y int, f func(int, int)) {
f(y, 2) // this becomes Add(1, 2)
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: