相关疑难解决方法(0)

正式,什么是typename?

有时我看到gcc在使用模板时吐出的一些非常难以理解的错误消息......具体来说,我遇到了一些问题,看似正确的声明引起了非常奇怪的编译错误,通过在"typename"关键字前加上前缀而神奇地消失了声明的开头...(例如,就在上周,我宣布两个迭代器作为另一个模板化类的成员,我必须这样做)...

关于typename的故事是什么?

c++ templates

116
推荐指数
6
解决办法
5万
查看次数

C++模板:返回list :: iterator

如何使以下代码有效?在编译期间,我收到一个错误,告诉我该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);
};
Run Code Online (Sandbox Code Playgroud)

另外,这是我如何定义searchForResource函数?

template<class t>
std::list<typename ResourceManager<T>::ResourceWrapper*>::iterator
    ResourceManager<T>::searchForResource(const std::string& file)
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

c++ templates

3
推荐指数
2
解决办法
4375
查看次数

标签 统计

c++ ×2

templates ×2