相关疑难解决方法(0)

Golang如何使用函数作为map的键

如何使用函数作为地图的关键?例如:

type Action func(int)
func test(a int) { }
func test2(a int) { }

func main() {
  x := map[Action]bool{}
  x[test] = true
  x[test2] = false
}
Run Code Online (Sandbox Code Playgroud)

这些代码会显示错误: invalid map key type Action

key function map go

8
推荐指数
4
解决办法
4606
查看次数

标签 统计

function ×1

go ×1

key ×1

map ×1