如何在模板化的类中声明模板化的map :: iterator.下面的代码说; 编译时预计

muk*_*kul 2 c++ templates stl compiler-errors map

以下代码表示错误:expected';' 在'forwit'错误之前:预期';' 在'revit'之前

template<class T>
class mapping {

public:
    map<T,int> forw;
    map<int,T> rev;
    int curr;
    //typeof(forw)::iterator temp;
    map<T,int>::iterator forwit;
    map<int,T>::iterator revit;
};

//    }; // JVC: This was present, but unmatched.
Run Code Online (Sandbox Code Playgroud)

我完全不知道问题是什么?请帮忙.

提前致谢

Sch*_*ron 9

为了帮助编译器理解您正在讨论模板化上下文中的类型,您必须帮助它编写typename.

在你的情况下

typename map<T,int>::iterator forwit;
Run Code Online (Sandbox Code Playgroud)