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
  • 195,986
  • 40
  • 382
  • 396
Johnas
  • 1,193
  • 2
  • 11
  • 22

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
  • 341,464
  • 111
  • 648
  • 831
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,136
  • 20
  • 29
0

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

Alexander Gessler
  • 44,353
  • 6
  • 80
  • 121