0

我正在尝试为 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

关于如何解决这个问题的任何想法?

4

1 回答 1

1

显然船长来营救了!

在'boost::ptr_vector::iterator'之前需要'typename'</p>

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

于 2013-10-19T10:16:11.317 回答