3

How to declare an iterator to

std::map <T, Point <T> *> ,

where:

template <typename T>
struct TList
{
    typedef std::vector < std::map <T, Point <T> *> >  Type;
};

In the following code

int main ()
{
    ....
    std::map <T, Point <T> *> ::iterator i_map;  //Error
    ...
}

g++ shows this error:

error: dependent-name `  std::map<T,Point<T>*,std::less<_Key>,std::allocator<std::pair<const T, Point<T>*> > >::iterator' is parsed as a non-type, but instantiation yields a type
note: say `typename  std::map<T,Point<T>*,std::less<_Key>,std::allocator<std::pair<const T, Point<T>*> > >::iterator' if a type is meant
Mat
  • 202,337
  • 40
  • 393
  • 406
Johnas
  • 1,263
  • 3
  • 12
  • 23

4 Answers4

5

Use typename as:

  typename std::map<T, Point <T> *>::iterator i_map;
//^^^^^^^^ here!

Because iterator is a dependent-name (as it depends on the map's type argument T), so typename is required here.

Read this FAQ for detail explanation:

Where and why do I have to put the "template" and "typename" keywords?

Community
  • 1
  • 1
Nawaz
  • 353,942
  • 115
  • 666
  • 851
0

Put "typename" before the line of error : std::map <T, Point <T> *> ::iterator i_map;.

Example:

typename vector<T>::iterator vIdx; 

// On your case : typename std::map <T, Point<T>*>::iterator i_map;

vIdx= find(oVector->begin(), oVector->end(), pElementToFind); //To my case
Alex
  • 265
  • 3
  • 6
0

Does typename std::map <T, Point <T> *> ::iterator i_map; work?

Boaz Yaniv
  • 6,334
  • 21
  • 30
0

What about typename TList<T>::Type::value_type::iterator?

Alexander Gessler
  • 45,603
  • 7
  • 82
  • 122