【发布时间】:2015-02-05 19:44:23
【问题描述】:
我有一个处理资源解析的系统(将名称与文件路径匹配等)。它解析文件列表,然后保存指向返回接口实现实例的函数的指针。
更容易展示。
resource.go
package resource
var (
tex_types map[string]func(string) *Texture = make(map[string]func(string) *Texture)
shader_types map[string]func(string) *Shader = make(map[string]func(string) *Shader)
)
type Texture interface {
Texture() (uint32, error)
Width() int
Height() int
}
func AddTextureLoader(ext string, fn func(string) *Texture) {
tex_types[ext] = fn
}
dds.go
package texture
type DDSTexture struct {
path string
_tid uint32
height uint32
width uint32
}
func NewDDSTexture(filename string) *DDSTexture {
return &DDSTexture{
path: filename,
_tid: 0,
height: 0,
width: 0,
}
}
func init() {
resource.AddTextureLoader("dds", NewDDSTexture)
}
DDSTexture 完全实现了Texture 接口,我只是省略了这些函数,因为它们很大,不是我的问题的一部分。
编译这两个包时,出现如下错误:
resource\texture\dds.go:165: cannot use NewDDSTexture (type func(string) *DDSTexture) as type func (string) *resource.Texture in argument to resource.AddTextureLoader
我该如何解决这个问题,或者这是界面系统的错误?重申一下:DDSTexture 完全实现了resource.Texture。
【问题讨论】:
标签: interface go callback return-value return-type