The problem is that the compiler can't know that
list<pair<K, V> >::iterator
is the name of a type. Even though the compiler has at that point seen the whole definition of
list so you would expect it to know
iterator is a name of a type inside
list, the C++ standard has rules that prevent it from knowing.
In this situation, I strongly prefer to use several typedefs to break up the ugly declarations. So you could fix your problem just by adding the keyword
typename to your declaration. But I personally think it is very ugly to use
typename that way anywhere other than right after the keyword
typedef
I haven't tested any of this, but I think it is right:
Code:
#include<list>
#include<utility>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
template<class K, class V> struct Hash{
typedef list<pair<K, V> > my_list;
typedef typename my_list::iterator iterator;
my_list *hash;
int (*hashFunction)(K key);
int buckets;
Hash(int (*hashFunction)(K), int buckets){};
~Hash(){};
iterator put(K key, V value, int pos_flag = -1){ return 0; };
};
Actually I prefer the following, but that makes changes further from the scope of your question
Code:
#include<list>
#include<utility>
#include<algorithm>
#include<string>
#include<vector>
template<class K, class V> struct Hash{
typedef std::pair<K, V> pair;
typedef std::list<pair> list;
typedef typename list::iterator iterator;
list *hash;
int (*hashFunction)(K key);
int buckets;
Hash(int (*hashFunction)(K), int buckets){};
~Hash(){};
iterator put(K key, V value, int pos_flag = -1){ return 0; };
};