Error defining HashMap::iterator type, please help

Discussion in 'C Programming' started by michaelmei, Oct 8, 2006.

  1. michaelmei

    michaelmei

    Joined:
    Oct 8, 2006
    Messages:
    3
    the main program:

    ----------------------------------------------
    include <hash_map>

    template<class A, class B>
    class HashMapTest
    {
    public:
    typedef hash_map<A, B> hashMap; //fine!!
    typedef hash_map<A, B>::const_iterator hashMapIter;
    /*GNU g++ compiler complains the hash_map<std::string, std::string>::const_iterator is not derived from class HashMapTest. Don't know what it exactly means... */

    };

    --------------------------------------------------

    I really dont know what is wrong with the const iterator for hash_map. Can anyone correct this code fragment?
    I am kinda stuck here...

    Thanks in advance.
    Last edited: Oct 8, 2006
    michaelmei, Oct 8, 2006
    #1
    1. Advertising

  2. michaelmei

    michaelmei

    Joined:
    Oct 8, 2006
    Messages:
    3
    the hash_map is under the namespace __gnu_cxx

    so

    that is:
    typedef __gnu_cxx::hash_map<K, T> dict;
    typedef __gnu_cxx::hash_map<K, T>::const_iterator dict_iter;

    can anyone pls help? Can't fix it now!
    michaelmei, Oct 9, 2006
    #2
    1. Advertising

  3. michaelmei

    michaelmei

    Joined:
    Oct 8, 2006
    Messages:
    3
    I think it is a type problem,
    if I use

    typedef hash_map<string, string>::const_iterator hm_iter;

    it compiles fine. But is there any way I can define an iterator type of a customized hash_map Key and Value (hash_map<K, T>::iterator)?

    Please help
    michaelmei, Oct 9, 2006
    #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. Vince Darley
    Replies:
    4
    Views:
    4,369
    emilchacko
    Mar 2, 2010
  2. KK
    Replies:
    2
    Views:
    498
    Big Brian
    Oct 14, 2003
  3. johny smith
    Replies:
    8
    Views:
    394
    Peter Koch Larsen
    Jul 2, 2004
  4. Rakesh
    Replies:
    10
    Views:
    12,132
    Mike Schilling
    Apr 8, 2008
  5. Urs Thuermann
    Replies:
    6
    Views:
    443
    Urs Thuermann
    Nov 4, 2011
Loading...

Share This Page