C ++ <T> :: iterator list cannot be used in derived class template
2 answers
In g ++. whenever in the template you see an error:
error: expected ';' before 'it'
Suppose you need a type name:
typename std::list<T>::iterator it;
This is necessary if a new type is declared in the template (in this case, a list iterator), which depends on one or more template parameters. The need is not unique to g ++ BTW, it is part of standard C ++.
+14
anon
source
share. , typedef , ( ):
template <typename T>
class myList : public std::list<T>
{
public:
typedef T value_type;
typedef const T const_value_type;
typedef value_type& reference;
typedef const_value_type& const_reference;
typedef value_type* pointer;
typedef const_value_type* const_pointer;
typedef std::list<T> base_container;
typedef typename base_container::iterator iterator;
typedef typename base_container::const_iterator const_iterator;
void foo ()
{
iterator it; // easy peasy
}
};
typedef.
+9