You are here:

C++/iterator declaration in C++ template under gcc


Hi, 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?



----- this snippet illustrates the problem ----

#include <list>

template<class T>

class CustomList



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;




  return false;


CustomListType& mGetItems(){ return aInternalList; };


CustomListType aInternalList;


Hello 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


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.