iterator

Discussion in 'C++' started by Douglas Dude, Jan 19, 2007.

  1. Douglas Dude

    Douglas Dude Guest

    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
     
    Douglas Dude, Jan 19, 2007
    #1
    1. Advertising

  2. Douglas Dude

    Kai-Uwe Bux Guest

    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
     
    Kai-Uwe Bux, Jan 19, 2007
    #2
    1. Advertising

  3. Douglas Dude

    Rolf Magnus Guest

    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();
     
    Rolf Magnus, Jan 19, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendrik Maryns
    Replies:
    18
    Views:
    1,467
  2. greg
    Replies:
    6
    Views:
    482
    Dietmar Kuehl
    Jul 17, 2003
  3. Replies:
    6
    Views:
    696
    Jim Langston
    Oct 30, 2005
  4. Steven D'Aprano

    What makes an iterator an iterator?

    Steven D'Aprano, Apr 18, 2007, in forum: Python
    Replies:
    28
    Views:
    1,267
    Steven D'Aprano
    Apr 20, 2007
  5. David Bilsby
    Replies:
    5
    Views:
    2,093
    David Bilsby
    Oct 9, 2007
Loading...

Share This Page