Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > iterator

Reply
Thread Tools

iterator

 
 
Douglas Dude
Guest
Posts: n/a
 
      01-19-2007
template<typename T>
void foo(std::map<std::string, T>&m){
std::map<std::string, T>::iterator it=m.begin();
//do something
}

That would fail on g++ at "it"
Is there another way around to use iterator with unknown T ? Thanks

 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-19-2007
Douglas Dude wrote:

> template<typename T>
> void foo(std::map<std::string, T>&m){
> std::map<std::string, T>::iterator it=m.begin();


typename std::map<std::string, T>::iterator it=m.begin();

> //do something
> }



Best

Kai-Uwe Bux

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      01-19-2007
Douglas Dude wrote:

> template<typename T>
> void foo(std::map<std::string, T>&m){
> std::map<std::string, T>::iterator it=m.begin();
> //do something
> }
>
> That would fail on g++ at "it"


It's always best to paste the error message into the posting.

> Is there another way around to use iterator with unknown T ?


Try:

typename std::map<std::string, T>::iterator it=m.begin();

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List iterator assignment fails, assert iterator not dereferencable David Bilsby C++ 5 10-09-2007 02:05 PM
What makes an iterator an iterator? Steven D'Aprano Python 28 04-20-2007 03:34 AM
Difference between Java iterator and iterator in Gang of Four Hendrik Maryns Java 18 12-22-2005 05:14 AM
How to convert from std::list<T*>::iterator to std::list<const T*>::iterator? PengYu.UT@gmail.com C++ 6 10-30-2005 03:31 AM
Iterator doubts, Decision on Iterator usage greg C++ 6 07-17-2003 01:26 PM



Advertisments