Compiler Error: Expected Nested Name Specifier before typedef

Compiler Error: Expected Nested Name Specifier before typedef

在具有两种实例化类型(TPT)的模板 class 中,我目前有以下行用于将 const_iterator 用于 class:

typedef typename std::vector< std::pair<T, PT> >::const_iterator const_iterator;

这在 C++11/14 环境中有效,但是在 C++98 环境中编译时(不幸的是,由于各种原因可能需要)我得到标题中显示的错误,expected nested name specifier before typedef.

有什么办法可以解决旧编译器的这个问题吗?

编辑:这是我的 class、

的基本结构
template<typename T, typename PT> class MyClass {

private:

    std::vector< std::pair<T,PT> > dataWithPriorityVec;    

    //... various private methods...

public:

    typedef typename std::vector< std::pair<T,PT> >::const_iterator const_iterator;

    //... constructors and various public methods...

};

您是否在 class 定义之前包括了 <vector><utility>

您需要"include what you use"以避免交叉编译问题。

无法保证 <utility>std::pair 需要)或 <vector> 包含在任何其他标准 headers 中。 如评论中所述。

因此,您用于 C++98 构建的编译器可能需要它才能正确编译。