GCC中标准库容器与模板嵌套使用问题(带模板迭代器不能识别)

template<class T>
inline static void Dumpvector(const std::vector<T *> &vvector)
{
    std::vector<T *> ::iterator pvectorIt = vvector.begin();
    for(; pvectorIt != vvector.end(); pvectorIt++)
    {
        (*pvectorIt)->dump();
    }
}

VC中上面语句是可以通过的。而GCC中使用带模板迭代器会编译出错,貌似是个类型不匹配错误,而直接使用迭代器原型则不会。如下

template<class T>
inline static void Dumpvector(const std::vector<T *> &vvector)
{
    __gnu_cxx::__normal_iterator<T* const*, std::vector<T*, std::allocator<T*> > > pvectorIt = vvector.begin();
    for(; pvectorIt != vvector.end(); pvectorIt++)
    {
        (*pvectorIt)->dump();
    }
}

具体原因不明,想是因为未包含相应宏定义,或者宏定义不支持模板,瞎猜,以后有时间再研究一番。^_^

最新的研究成功出炉:c++ 模板参数做容器参数,迭代器报错 vector<T>::const_iterator

原文地址:https://www.cnblogs.com/dongzhiquan/p/2016632.html