I have to declare Iter as typename but no typedef.
Then, I cannot use Iter in my template class declaration => frustrating :(
Please teach me how to use Iter, or else explain me why C++ is so nasty...
template <typename T>
struct MyContainer
{
typedef std::vector<T> Vec;
typename Vec::iterator Iter;
void Fo (typename std::vector<T>::iterator); //ok
typename std::vector<T>::iterator Ba(); //ok
void Foo (Iter); //error: 'Iter' is not a type
Iter Bar (); //error: 'Iter' does not name a type
}; //(gcc 4.1.2)
- Why
typedefcannot be used to declareIter? Why not? - How to use
Iterwithin thetemplateclass? (e.g. as function parameter type)
EDIT
In the instruction typename Vec::iterator Iter; the keyword typename says Vec::iterator is a type (i.e. not a static member function/attribute). Therefore, Iter is not declared as a type, but as a variable using the type Vec::iterator.