在自定义哈希表头文件中包括自定义链表

Include custom Linked List in custom Hash Table header files

本文关键字:自定义 包括 链表 表头 哈希 文件      更新时间:2023-10-16

我正在尝试创建自己的哈希表以使用我已经创建的链表。链表位于一个单独的文件夹中,Codenvy不允许我在头文件中使用它。

我尝试过相对和绝对途径,例如:

#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

我期望 c++ 允许由自定义对象组成的数组,但我可能大错特错了。错误是:

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

尝试:

LinkedList<T> table[size];

请记住:数组的大小必须是恒定的,并且在编译时是已知的