2013-10-19 55 views
0

我試圖做出的boost :: ptr_vector和IM只是有一點麻煩的迭代工作容器類..構成容器類的boost :: ptr_vector

這裏的成員之一功能IM試圖實現:

//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

船長明顯的救援!

需要 'typename的' 前 '的boost :: ptr_vector ::迭代'

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

+0

感謝,有什麼白癡.. heheh,如果你想不出告訴我剛學的模板: d – guskenny83

相關問題