You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
328 B

3 years ago
package main
import "errors"
func main() {
tt("*")
}
func add(a, b int) int {
return a + b
}
func sub(a, b int) int {
return a - b
}
func tt(s string) (func(a, b int) int, error) {
switch s {
case "+":
return add, nil
case "-":
return sub, nil
default:
err := errors.New("输入错误")
return nil, err
}
}