c++boostcontainersptr-vector

making a container class for boost::ptr_vector


i am trying to make a container class for boost::ptr_vector and im just having a bit of trouble getting the iterator to work..

here is one of the member functions im trying to implement:

//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);
}

the error i am getting is:

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

any ideas of how to fix this?


Solution

  • Captain Obvious to the rescue!

    need ‘typename’ before ‘boost::ptr_vector::iterator’

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