1

I have an assignment where I need to implement a hash table class including an iterator class to it. I've defined the class Hash:

template <class KeyType, class ValueType>
class Hash
{
    class Pair
    {
    public:
        Pair(KeyType a_key) :
        m_key(a_key)
        {
        }
        Pair(KeyType a_key, ValueType a_val) :
        m_key(a_key), m_val(a_val)
        {
        }

        KeyType m_key;
        ValueType m_val;    
    };

public:
    typedef size_t (*HashFunc)(KeyType);

    class Iterator
    {
        friend class Pair;
    public:
        //Iterator()
        //Iterator(const Iterator& a_other)
        //Iterator& operator=(const Iterator& a_other)
        //~Iterator

        void operator++();

        ValueType& operator*() { return *m_itr->m_val;}

    private:
        typedef typename std::list<Pair*>::iterator m_itr;
        size_t m_hashIndex;
    };

    Hash(size_t a_size, HashFunc a_func);
    ~Hash();

private:
    HashFunc m_hashFunc;
    size_t m_size;
    std::list<Pair*>*  m_hash;
};

and in line ValueType& operator*() { return *m_itr->m_val;} I get the following error: expected primary-expression before ‘->’ token and I can't find the problem. Can anyone offer some advice? Thanks in advance!

1 Answer 1

3

This

typedef typename std::list<Pair*>::iterator m_itr;

is a typedef that declares an alias type for std::list<Pair*>::iterator called m_itr. I suppose you wanted to have a member of that type:

typedef typename std::list<Pair*>::iterator itr_type;
itr_type m_iter;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.