错误示例@play.golang.org:http ://play.golang.org/p/GRoqRHnTj6即使接口完全为空,以下代码也会返回“prog.go:16: cannot use NewMyGame (type func() MyGame) as type func() Playable in return argument”。也请找到下面附带的代码,不幸的是我完全被难住了,任何帮助将不胜感激。package main// Define an arbitrary game typetype MyGame struct{}// Create a constructor function for arbitrary game typefunc NewMyGame() MyGame { return MyGame{}}// Define an interface defining game typestype Playable interface{}// In my app it will return a list of constructors matching interfacefunc Playables() func() Playable { return NewMyGame}func main() {}
1 回答
UYOU
TA贡献1878条经验 获得超4个赞
就像错误所说的那样,
cannot use NewMyGame (type func() MyGame) as type func() Playable
一个简单的解决方法是
func Playables() func() Playable {
return func() (Playable) {
return NewMyGame()
}
}
- 1 回答
- 0 关注
- 171 浏览
添加回答
举报
0/150
提交
取消