Include custom Linked List in custom Hash Table header files

134 views Asked by At

I am trying to create my own Hash table to use my Linked List I have already created. The linked list is in a separate folder and Codenvy won't allow me to use it in a header file.

I have tried relative and absolute pathways like:

#include "../LinkedList/LinkedList.h"

#ifndef HASH_TABLE
#define HASH_TABLE
#include "../LinkedList/LinkedList.h"

template <typename T>
class HashTable {
    public:
        HashTable(); // Constructor
        ~HashTable(); // Destructor
        void add (T); // add to the corresponding list
    protected:
        LinkedList<T>[] table; // includes linked lists to carry all data
    private:
        int hashIndex (T); // Finds the index of an element


};

#endif

I was expecting that c++ would allow for an array to be constituted of custom objects, but I am probably very wrong. Errors were:

In file included from Main.cpp:2:0:
HashTable.h:12:22: error: expected unqualified-id before ‘[’ token
         LinkedList<T>[] table;
                  ^
1

There are 1 answers

0
chessprogrammer On

Try:

LinkedList<T> table[size];

Remember: the size of the array must be constant and known at compile time