C ++, iterator on std :: map

How to declare an iterator

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
+3
source share
4 answers

Use typenameas:

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

Because it iteratoris a dependent name (because it depends on the argument of the type of map T), therefore typenameit is required here.

Read this FAQ for a detailed explanation:

Where and why do I need to put a "template"? and "typename" keywords?

+5
source

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

0
source

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

0

"typename" : std::map <T, Point <T> *> ::iterator i_map;.

:

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
0

All Articles