C++/iterator declaration in C++ template under gcc
Expert: Eddie - 2/7/2008
QuestionHi, I'm need to write cross-platform code. I wrote a custom list which compiles and works fine in MS visual studio 2003 but does not compile with G++ on linux. (gcc version 4.1.1 20070105 (Red Hat 4.1.1-51))
There error which appears for the 2nd typedef line ( the one for the iterator ) states this:
type "std::list<T, std::allocator<_CharT> >" is not derived from type "CustomList<T>"
I can not figure out what is wrong and how to fix it.. Can you help?
Thanks,
Daniel
----- this snippet illustrates the problem ----
#include <list>
template<class T>
class CustomList
{
public:
typedef std::list< T > CustomListType;
typedef std::list< T >::iterator CustomListIterType;
bool FindItem(int pParam, T& pItem)
{
CustomListIterType lIter;
lIter = aInternalList.begin();
while( lIter != aInternalList.end() )
{
if( (*lIter)->SomeCall(pParam) == true )
{
pItem = (*lIter);
return true;
}
lIter++;
}
return false;
};
CustomListType& mGetItems(){ return aInternalList; };
private:
CustomListType aInternalList;
};
AnswerHello Daniel, thank you for the question.
Could you please include your declaration wherever you are using this list? I'm assuming you are using it for std::strings based on the error, but it could be something else.
Template code isn't actually compiled until it is instantiated, and I need to see the template object declaration in main or wherever it might be to understand that error.
- Eddie