//多态
package main
import "fmt"
type Functype func(int, int) int//定义函数类型
func Calc(a int, b int, fun Functype) int {
result := fun(a, b) //回调机制
return result
}
func Add(a, b int) int{
return a + b
}
func Munic(a, b int) int {
return a - b
}
func Mult(a, b int) int {
return a * b
}
func main() {
result := Calc(3,6, Add)
fmt.Println("result = ", result)
}
有疑问加站长微信联系(非本文作者)