为boost :: ptr_vector创建一个容器类

时间:2013-10-19 10:13:02

标签: c++ boost containers ptr-vector

我正在尝试为boost :: ptr_vector创建一个容器类,我只是在让迭代器工作时遇到一些麻烦..

这是我试图实现的成员函数之一:

//data is of type boost::ptr_vector<T>
//Date is a custom date class that i made with > operator overloaded

template <class T>
void P_VContainer<T>::addElementByDate(T* item)
{
    boost::ptr_vector<T>::iterator it;

    for(it = data.begin(); it < data.end(); it++)
    {
        T temp = *it;
        Date = *lhs = item->getDate();
        Date = *rhs = item.getDate();

        if(*lhs > *rhs)
        {
            data.insert(it, item);
            return;
        }
    }
    data.insert(it, item);
}

我得到的错误是:

p_vcontainer.cpp: In member function ‘void P_VContainer<T>::addElementByDate(T*)’:
p_vcontainer.cpp:52:2: error: need ‘typename’ before ‘boost::ptr_vector<T>::iterator’ because ‘boost::ptr_vector<T>’ is a dependent scope
p_vcontainer.cpp:52:33: error: expected ‘;’ before ‘it’
p_vcontainer.cpp:54:7: error: ‘it’ was not declared in this scope

有关如何解决此问题的任何想法?

1 个答案:

答案 0 :(得分:1)

船长明显拯救!

  

在'boost :: ptr_vector :: iterator'

之前需要'typename'

typename boost::ptr_vector<T>::iterator it;