【发布时间】:2019-02-02 15:20:07
【问题描述】:
我正在尝试在我的结构中发挥成员的作用
type myStruct struct {
myFun func(interface{}) interface{}
}
func testFunc1(b bool) bool {
//some functionality here
//returns a boolean at the end
}
func testFunc2(s string) int {
//some functionality like measuring the string length
// returns an integer indicating the length
}
func main() {
fr := myStruct{testFunc1}
gr := myStruct{testFunc2}
}
我收到错误:
Cannot use testFunc (type func(b bool) bool) as type func(interface{}) interface{}
Inspection info: Reports composite literals with incompatible types and values.
我无法弄清楚为什么会出现此错误。
【问题讨论】: