*** UPDATE ****在指針數組中的鏈表中創建對象時編譯錯誤:C++
所以開始我試圖嘗試哈希。爲了儘量縮短它,我創建了一個需要一個通用參數的linkedlsit類。我有一個哈希表類,我試圖創建(我相信)鏈表指針(牢記的LinkedList需要一個通用型)
所以,在我的哈希表類,我有一個私有變量的陣列,使得
SLL< Entry <string, int> >** list;
其中SLL是我的鏈表,Entry是持有一個鍵(字符串)和值(int)並綁定它以使其成爲一個指針數組的對象。
在哈希表構造我創建像這樣
list = new SLL<Entry<string, int> > * [this->size];
現在
在我的代碼,我嘗試我的哈希碼功能後,追加Entry對象到數組結束
list[hash]->append(new Entry<string, int>(key, e));
但它得到這個錯誤
HashTable.h: In member function 'void HashTable::createEntry(std::string, int)':
HashTable.h:78:53: error: no matching function for call to 'SLL<Entry<std::basic_string<char>, int> >::append(Entry<std::basic_string<char>, int>*)'
list[hash]->append(new Entry<string, int>(key, i));
它的工作原理如果我將條目替換爲鏈接中的對象edlist作爲jsut一個int,或浮動,甚至字符串
所以,這可能是什麼原因造成的?請和謝謝你,如果你需要任何更多的信息,讓我知道:)
#ifndef SLL_H
#define SLL_H
template <class T>
class SLL
{
private:
Node<T>* head;
Node<T>* tail;
int size;
public:
SLL();
virtual ~SLL();
void append(T&);
void append(T*);
void prepend(T);
void deleteElem(int);
void toString();
int getSize();
void insertAt(T, int);
T retrieveDataAt(int);
};
#endif /* SLL_H */
template <class T>
SLL<T>::SLL()
{
this->tail = NULL;
this->head = NULL;
this->size = 0;
}
void SLL<T>::append(T data)
{
//do stuff
this->head = new Node<T>(data);;
}
是否'SLL'有一個成員函數,看起來像'追加(T *)'?我認爲你需要努力縮小與此相關的代碼(並更新你的問題),否則幾乎無法繼續。 –
cartographer
2014-12-07 03:47:25
更新了SLL類除了幾個函數,所以我沒有附加(T *)即時猜測,類(對象)需要作爲指針傳遞,因此T *部分? – 2014-12-07 05:45:55