iterators in hash_map data

Started by
0 comments, last by JeroMiya 21 years, 5 months ago
I would like to use a structure as the data for a hash_map, and I want the structure to contain iterators to elements in the hash_map, but the compiler is giving me errors. For example, this code would give an error:
  
#include <iostream>
#include <hash_map>


using namespace std;

template<class T>
class HashData
{
    public:
        hash_map<T, HashData<T>, hash<T>, equal_to<T> >::iterator it;

};


int main()
{
    HashData<int> bob;

    return 0;
}

Errors:

stl_pair.h: In instantiation of 'pair<const int, HashData<int> >':

stl_hashtable.h:239:  instantiated from '_Select1st<pair<const int,HashData<int> > >'

stl_hashtable.h:239:  instantiated from 'hashtable.h:239:  instantiated from 'hashtable<pair<const int,HashData<int> >,int,hashallocator<HashData<int> > >'

test.cpp:11:  instantiated from 'HashData<int>'
test.cpp:18:  instantiated from here

stl_pair.h:39: invalid use of undefined type 'class HashData<int>'
test.cpp:13: forward declaration of 'class HashData<int>'
stl_pair.h:50: confused by earlier errors, bailing out

   
Is this just something that you can't do, or am I doing something incorrectly? Jeremy Bell [edited by - Magmai Kai Holmlor on November 3, 2002 9:10:23 PM]
Advertisement
I believe you can''t do that. You must store pointers to HashData, instead of HashData objects themselves.

  hash_map<T, HashData<T>* >::iterator it;  


C++: Boost | GOTW tips | GOTW articles | FAQ lite | CUJ

This topic is closed to new replies.

Advertisement