Sunday, September 4, 2011

C++ list::iterator cant be used

g++ compiler may give this error: expected `;' before 'it'
template <typename T>
class MyClass
{   public:
  void func() 
    std::list<T>::iterator it;
The solution is simple, you need add "typename" in front of your declaration of iterator.

typename std::list::iterator it;
This is needed when you have a new type declared which is dependant on one or more of the template parameters.

You may also find an answer from here:

No comments:

Post a Comment