2012-01-29 66 views
1

我是C++新手,嘗試編寫HashTable數據結構。 我已經使用模板將其寫入了泛型,並且我已經包含了一個HashEntry對象以用於對碰撞進行簡單的二次探測。 我的代碼是:無匹配函數調用

(在.c文件是#包括是下面的類定義.H文件):

HashEntry::HashEntry() 
    { 
     this->isActive = false; 
    } 

和相關.H文件與類定義是:

#include <iostream> 
#include <string> 
#include "Entry.C" 
using namespace std; 

#define Default_Size 50000 

class HashEntry; 

template <class T> class HashTable 
{ 
private: 
    int size; 
    int occupied; 
    T array[Default_Size]; 

public: 
    HashTable(); 
    int Size(); 
    void Add(T t); 
    void DebugAdd(T t, int index); 
    T* Get(string index); 
    /* How do I declare the existence of HashEntry BEFORE here? */ 
    int FindNextOpen(HashEntry he); // Only works for hash_entry objects! 
    int Hash(string str); 
    void Rehash(); 
}; 

class HashEntry 
{ 
private: 
    Entry e; 
    bool isActive; 

public: 
    HashEntry(); 
    HashEntry(Entry e); 
    bool IsActive(); 
    Entry GetEntry(); 
}; 

每當我試着和編譯的一切,我得到的錯誤之上的HashEntry構造: 「爲調用輸入::沒有找到匹配功能()」 ......「候選人......」。 我不知道它是什麼意思 - 當我嘗試包含一個默認的Entry()構造函數(我的第一個解釋)時,它會拋出更多的錯誤。

感謝您的幫助!

更新 - ENTRY.C:

#include "Entry.H" 
/* ***Entry Methods*** */ 
/* 
* Overloaded Entry obejct constructor that provides a string value. 
*/ 
Entry::Entry(string s) 
{ 
    this->value = s; 
    this->count = 0; 
} 

/* 
* Returns the number of times this Entry has been accessed/ 
* found. 
*/ 
int Entry::Count() 
{ return this->count; } 

/* 
* Returns the string value stored in the Entry object. 
*/ 
string Entry::Value() 
{ return this->value; } 
+2

你能告訴我們Entry.C的內容嗎? – 2012-01-29 05:21:43

+0

該問題似乎在Entry.C文件中。你能提供這個來源嗎? – scientiaesthete 2012-01-29 05:23:15

+1

您使用C++進行編程,但您的文件具有'.c'擴展名?它確實應該有一個'.cpp'擴展名,因爲'.c'通常意味着一個C源文件。有些編譯器實際上會根據文件擴展名更改其編譯模式。 – 2012-01-29 05:23:40

回答

0

我發現了這個問題。 錯誤消息表明「Entry :: Entry()」沒有匹配的函數調用。因爲在任何情況下我都沒有創建Entry對象,所以我不知道它是什麼意思。 我試着爲類Entry添加一個顯式的默認構造函數並解析。

感謝大家的幫助!

+0

Re「因爲在任何情況下我都沒有創建Entry對象」:當然可以。你的類'HashEntry'有一個數據成員'e',它是'Entry'。每次創建'HashEntry'時,都會創建一個'Entry'。 – 2012-01-29 20:24:55

3

並與類定義相關的.h文件是:

#include <iostream> 
#include <string> 
#include "Entry.C" 

哇!永遠不要在頭文件中包含源文件。

您的Entry.C應該不存在。相反,在你的頭定義構造函數,類定義中:你有沒有告訴我們

class HashEntry 
{ 
private: 
    Entry e; 
    bool isActive; 

public: 
    HashEntry() : isActive(true) {} 
... 
} 

一件事是類Entry的定義。這是你問題的根源之一。當你沒有向我們展示造成它的事情時,要確定你的問題有點難。

+0

這是一個非常好的觀點。 我編輯了我原來的帖子以包含Entry.C的源代碼。 – 2012-01-29 19:18:34