我怎样才能使下面的代码工作?在编译过程中,我收到一条错误消息,告诉我searchForResource
函数没有返回类型。
template<class T>
class ResourceManager
{
private:
struct ResourceWrapper;
std::list<ResourceWrapper*> resources_; // This compiles fine
std::list<ResourceWrapper*>::iterator // Error occurs here
searchForResource(const std::string& file);
};
另外,这就是我如何定义searchForResource
功能?
template<class t>
std::list<typename ResourceManager<T>::ResourceWrapper*>::iterator
ResourceManager<T>::searchForResource(const std::string& file)
{
// ...
}
std::list<ResourceWrapper*>::iterator
编译器很难理解。前缀为typename
在实现和声明中让编译器知道它是一种类型。
Like so:
typename std::list<ResourceWrapper*>::iterator searchForResource(const std::string& file);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)